- Home /
Collision.contacts?
Is there some sort of odd order that Collision.contacts follows? Every time I use my functions, it keeps switching around and such.
What I really want to do is determine all the walkable normals the character is touching, and his surface is the average of all those normals. I know the average would require Lerping, but what of the normals he's standing on? How could I go about reading those fluently?
Answer by jameslee0227 · Nov 18, 2010 at 08:20 AM
recommand
use unity help
sample raycast
RaycastHit hit;
if(Physics.Raycast(rigidbody.position, Vector3.down, out hit))
3.OnCollision
void OnCollisionEnter(Collision collision)
{
#region DRAW COLLISION NORMAL Vector3 refrectionDirection = Vector3.zero; foreach (ContactPoint contact in collision.contacts) { Debug.DrawRay(contact.point, contact.normal*10, Color.white);
refrectionDirection += contact.normal;
}
collisions.Add(collision.contacts);
#endregion
}
void Update() {
foreach (ContactPoint[] contacts in collisions)
{
foreach (ContactPoint contact in contacts)
{
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
}
}
Woot! This worked perfectly.
Given, now I have to use a method for keeping my character vertical than changing transform.rotation, but the surface is now perfect!
Just a comment that contact.normal is not the surface normal. It's the collision normal, which is the direction in which the 2 objects want to push away from each other.
To get the surface normal accurately you would want to raycast to that contact.point, and then use the raycast's hit.normal.