Hey guys,
I am having major issues with the collider/collision concept it seems and I need a few clarifications.
The concept I am trying to make is like a submarine boat that uses sonar to detect other ships in the ocean. The boat itself has a collider (like a tube for its shape).
I added an empty GameObject, gave it a rigidbody component with zero mass and ‘Is Kinematic’ = true; and then added a sphere collider to the empty GameObject that can be adjusted to reach many hundreds of feet if necessary. I made this empty GameObject a child object of the boat.
Ideally, what I want to know is this:
- If two sonar detection signals (sphereColliders) bump into each other, to detect a collision and report what transform the boat is (by using the parent information of course)
- Do the OnCollisionEnter/Stay/Exit functions only work when the collision happens on the surface of the Collider? what happens if something is already inside the bounds of the collider? ( I ask this because I’m trying to report using Debug.Log(contact.otherCollider.name) and there is nothing to report even though my sample boats are all within range of each other).
I need some help with code that actually works because my usage of OnCollisionEnter and such is doing nothing at all in regards to collider detections.
// Code //
public SphereCollider sonarCollider;
start(){sonarCollider.enabled = true;}
void OnCollisionStay(Collision collision) {
foreach (ContactPoint contact in collision.contacts) {
Debug.Log(contact.thisCollider.name + " hit " + contact.otherCollider.name);
print(contact.thisCollider.name + " hit " + contact.otherCollider.name);
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
}
… and yet nothing is happening…