I'm new to Unity and struggling to get the OnCollisionEnter function to pick up.
I realize this sounds similar to other questions, but I still can't get it to work for my case.
I'm using the Oculus Distance Grab Sample Scene.
I've got a block trying to run into a soccer ball ;)
The block has a box collider (non trigger) and rigid body (non gravity, non kinematic).
The soccer ball has a Sphere Collider (non trigger) and a rigid body (yes gravity, non kinematic).
The block contains a script component that makes it float over to the ball and run into it.
The ball has a script with the OnCollisionEnter function that is supposed to destroy the block upon contact.
Here's the Player script attached to the ball.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
void OnCollisionEnter (Collision col) {
FloatingItem item = col.collider.gameObject.GetComponent<FloatingItem>();
Destroy(item);
}
}
The ball is in the Player layer and the block in the Attacker layer. I double checked collision were enabled between these layers in the Player Settings collision matrix.
Also, the colliders of each object seem to be the size they should to match the mesh.
Any help to get the collisions working would be wonderful!
Here's a visual of the settings as well:
UPDATE:
Here is the floating block's Update method:
void FixedUpdate () {
if(targetTransform != null) {
this.transform.position = Vector3.MoveTowards(this.transform.position, targetTransform.transform.position, Time.deltaTime * moveSpeed);
}
}
I have been trouble getting any debug logs to show in the console so they haven't been reliable. But the answer was that the collision was in fact working but that I was destroying the wrong object.
Changing it to Destroy(col.collider.gameObject) works. An important distinction learned here! Thanks!
UPDATE 2:
I've added an image of how the OVRPlayerController is setup. Trying to read through the weak documentation about the character controller component of this but my understanding is that it contains a capsule collider.



The block contains a script component that makes it float over to the ball and run into it.Spoiler: Anything having a Rigidbody should only be moved viaMovePositionwithinFixedUpdateotherwise Physics don't work well. If the block is moved by script you might also want to enableisKinematicexcept it shall react to Physics - derHugoevery framethough but in fixed time intervals (usually 0.2 seconds) - derHugo