how to cause to character contorller to rotate when it collide the wall?
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612082145im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 0 Answers
How to script float the object for add to state machine 0 Answers
Can someone please help me find out what wrong with my code. 0 Answers
How to get a public int equal the same number when added in all object that have the same script? 1 Answer
Is it possible to make multiple prefabs out of a single prefab for use in the map editor? 0 Answers