- Home /
Collision angle of collided
Hi all,
I'm using :
OnControllerColliderHit (ControllerColliderHit hit)
I wish to align my collider with the angle of the face it collided with on the collision object. Let me explain better :-)
Suppose a body collides with a cube; irrespective of it's collision angle I wish it to rotate to be flush with the cube's side i.e. so it matches the cube's collided with face angle - sorry, not a great explanation!
Hope that's clear enough for someone to help. I was thinking that somehow I get the dot product of the collision and then use that somehow to align the collider with the cube's face - but not sure...
Cheers
Answer by DavidDebnar · Oct 17, 2011 at 09:17 PM
If you want to get the rotation between the two points in space, cube and a sphere, you should use something like this:
OnControllerColliderHit(hit : ControllerColliderHit)
{
Cube1.rotation = hit.collider.transform.Vector3 - Cube1.Vector3;
}
If you want more information about aligning faces to other ones, there is a nice Faux/Spherical script on the forums, link.
David
Hi $$anonymous$$,
Thanks for the reply. I used the code you mentioned and achieved what I was after.
Thanks again
No problem. It's like balance in karma. I ask questions, others answer. Others ask, I answer :).
Your answer
Follow this Question
Related Questions
Collisions with CharacterController? 0 Answers
Increase score when hit by a prefab help? 2 Answers
OnCollisionEnter Issues 2 Answers
Ball issue and question 0 Answers
Tree collisions do not work 2 Answers