- Home /
The question is answered, right answer was accepted
Drifting code not 100% accurate?
I'm trying to check if the car is facing the forces direction. but the two angles are always offset by around 3%-5% when driving in a straight line. Any help would be appreciated as this has halted the progress of my project.
Answer by VesuvianPrime · Aug 21, 2015 at 12:39 PM
Perhaps instead of trying to reinvent the wheel just use Vector3.Angle
Vector3 forward = car.transform.forward;
forward.y = 0.0f;
Vector3 velocity = car.rigidbody.velocity;
velocity.y = 0.0f;
float angleVelocityOffset = Vector3.Angle(forward, velocity);
if (angleVelocityOffset > 60)
{
//car is drifting
}
The angleVelocityOffset seems to stick at 90 no matter what I do? Not sure if this is due to my setup or the code. (This is a topdown setup)
I would be interested to see the hierarchy of your car objects. Do the rigidbody and transform belong to the same GameObject?
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Making car shift gears without set speed limit 1 Answer
Multiple Cars not working 1 Answer
Similar movement to a game (look description) 1 Answer
Rotating an Arrow 2 Answers