Currently I’m developing a game with cars.
I’m using character controller because I want to use characterController.simpleMove
and because I want to use the characterController stairs feature.
i want that when the car will collide the wall it will turn in a way that the angle between the normal and the car before the collide will be equal to the angle between the normal and the car after the collide:
I succeed to write code that do it with rays:
void OnCollisionEnter(Collision collision) {
RaycastHit hit;
if (Physics.Raycast(transform.position, collision.contacts[0].point, out hit ,100 , bumpers))
{
if (debug)
{
Debug.DrawRay(hit.point,hit.normal * 20 ,Color.blue,1);
Debug.DrawRay (hit.point,transform.forward * (-20) , Color.magenta,1);
Debug.DrawRay (hit.point, ((20 * hit.normal) - ((-20) *transform.forward )) , Color.red,1);
}
}
}
void Start ()
{
bumpers = LayerMask.GetMask ("bumpers");
}
this is how it looks when I put the context of OnCollisionEnter method in update method:
its work too when I put the code only in the OnCollisionEnter at the clash time.