Im making a police simulator that requires traffic simulation like GTA4.
I currently have the vehicles driving around following nodes. The main problem i have is that when the vehicles detect something infront they slam on the brakes until the obstacle is no longer infront. I have come here to ask how i can work out how much braking needs to be applied to stop just before the obstacle.
Im using Unity3D, so i can get the velocity and the distance to the object.
Here is the code im using to make the vehicle brake:
RaycastHit rayHit = new RaycastHit();
if(Physics.Raycast(rayPos2, transform.forward, out rayHit, reactionDistance))
{
hitDistance = Vector3.Distance(rayPos2, rayHit.point);
float brakeAmount = (stoppingAmount * rigidbody.velocity.magnitude) / hitDistance;
flWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1);
frWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1);
rlWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1);
rrWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1);
}
If its easier to contact me via email or skype then here's my details:
Skype: kieranc12
Gmail: kieranchandler15@gmail.com
Any help would be greatly appreciated