- Home /
OnCollisionEnter question....
I am creating a footsteps script with my capsule collider-based player: I am having an issue with collision detection.... If i am on a surface below me and i collide with a new surface in front of me (such as a wall), the collision detection chooses the wall (concrete) sound to play, instead of the ground that i am standing on. Is there a way to make sure that the collision contact is only hitting the bottom of my capsule collider? Thanks
The angry bots project has an example in it. Think they might have used a raycast downward.
how would i use a raycast alongside collision detection? If the collided gameobject is equal to the object that the raycast downward detected, then that object is the surface sound we should play?
You wouldn't need to do both. The raycast downward is more accurate. I suggested you see how they do it in the angry bots project, however, because I don't remember all the specifics of their implementation. Again, it's worth a look.
ok thanks, and wouldn't all of those constant raycasts be quite performance expensive?
No. A raycast is relatively cheap. Try it yourself by casting a ray 1000 times each frame if you wish. Generating the HitInfo is a bit costly, but not as much as generating collision info. Finally, you should only need to cast periodically, to check which sound to play, so it's not going to be happening every frame, right?
Answer by greatwhiteshark17283 · Jan 01, 2014 at 10:33 PM
What you could do is add a collider under the capsule player and make it a child of the player. You could also add a script to the player which detects the tag of the object it's colliding with.
var objectTag : String;
function OnCollisionEnter(col : Collider){
if(col.tag == objectTag){
//add the sound part here
}
}
the issue with this is, if the collider under the capsule player is touching the capsule player then it causes collider issues, as one collider is inside of rigidbody; we get physics issues.
i need to use oncollsionenter so i can access contact data
OnTriggerEnter does not handle collision information, just detects if there was a collision. So i cannot find the point of collision unless i use OnCollisionEnter
Your answer
Follow this Question
Related Questions
Trouble with Physics.IgnoreCollision 0 Answers
Unwanted jittery behavior 2 Answers
Colliders in a wall jut out 0 Answers