- Home /
Can static objects detect collisions
Is it possible for a static object to detect collisions with a player using a character controller, i am currently using 'OnControllerColliderHit()' on the player script to find the static object and trigger any scripted event that i want.
Want i want to know is if the static object's script can detect when the character controller collides with it and trigger the event itself rather than the player script having to reference the static object and tell it what to do.
I have tried using 'OnCollisionEnter()' on the static object's script but it seem to only detect the collision if the the object i want to be stationary is moving, rather than when something else collides with it.
Thanks for any help
Answer by Bunny83 · Apr 21, 2013 at 10:39 PM
No, not really. static objects can't detect anything. Only active components like a Rigidbody or the CharacterController can. True collisions are handled by the physics system. This always requires at least one rigidbody.
In general all moving objects should have a rigidbody. static object are per definition "static" and should never move and therefor can't detect collisions. It's always the rigidbody that detects collisions, even when you move a static collider (which you shouldn't) into a rigidbody the collision is detected by the rigidbody but only when the rigidbody is awake. If a RB doesn't move it falls asleep. When you move the rigidbody it wakes up again.
Take a look at the table at the bottom of this page
The CharacterController is another case. It doesn't produce collision messages since from the Physics system's point of view it's a static collider. The CC does it's own collision detection (OnControllerColliderHit). For more details see the CharacterController component page
So your basically saying that if I want something like a stationary object (maybe a target) to know if it has been hit by something else that is using a character controller for movement, then either the stationary object needs a rigidbody attached or the character controller needs to tell the target "hey i collided with you, do something"
Yes, that would be a way. You could use Send$$anonymous$$essage in OnControllerColliderHit to invoke your own "event" on the hit-object.
Seems like there should be a way for an object itself to know if something else has hit it, but I guess I'm just being picky :P
Thanks for the help
There is. You can set the target's collider to Is Trigger and you'll get the OnTrigger events. Here's a chart of what triggers what: http://answers.unity3d.com/storage/attachments/2050-interactionmatrix.png
Edit: Character colliders are a special case. They'll fire OnTrigger events on trigger colliders even though there's no rigidbody involved. They won't fire OnCollision events though.
@Nition:
Why linking a custom uploaded image when there is the manual. Anyways, for any collision or trigger messagees you need a rigidbody. The character controller doesn't use the physics system. From the physicssystem's point of view the CharacterController is just a CapsuleCollider.
Answer by cbranch101 · Apr 21, 2013 at 03:04 PM
It should, as long as you have colliders in both both objects. Are you sure you have a collider in your static object?