- Home /
How to detect my car is drifting or not ?
I am making a drift game. I want to add score points and compliments on during the car drift. How can i detect now my car is drifting and now my car is going straight i-e not drifting ?
Never done this but if you use wheelcolliders you could check if the back wheels are facing the same direction as the car rigidbody velocity? Or check if their difference is bigger than a few degrees.
@JedBeryll This seems helpful. I will try this. Thank you so much. :)
I also thought about something like this - thanks for verification! :)
Answer by Edy · Aug 11, 2016 at 10:48 PM
Compute the dot product among the velocity vector (Rigidbody.velocity) and the car's heading (Transform.forward):
If result is 1, the car is just driving normally.
If result is 0, the car is sliding laterally.
Values in between can represent the amount of "drifting" of the car. You can also get the exact angle of drifting in degrees, and give more points with more angle and velocity:
float driftValue = Vector3.Dot(GetComponent<Rigidbody>.velocity, transform.forward);
float driftAngle = Mathf.Acos(driftValue) * Mathf.Rad2Deg;
Hi @Edy. I have tried it, but on reverse movement of car result is zero. I'm trying to count car drifts in a game and i am using car with RCC. Please help to sort out this issue. Thanks
if you use normalized velocity then you will get more accurate results secondly @meMUmar when you reverse the car then you should multiply the transformed with -1 float driftValue = Vector3.Dot(GetComponent.velocity.normalized, transform.forward); float driftAngle = Mathf.Acos(driftValue) * Mathf.Rad2Deg;
Answer by AnderSystems · May 17 at 04:25 AM
try this:
Vector3 driftValue = transform.InverseTransformVector(rb.velocity); _driftAngle = (Mathf.Atan2(driftValue.x, driftValue.z) * Mathf.Rad2Deg);
it returns the positive and negative angle of drifting value.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Can anyone help me make portals (like Valve's) 2 Answers
Rigidbody character controller can't walk on stairs 0 Answers
3D Hook With Swing Physics 0 Answers