- Home /
Measure speed in single axis
So I'm making a simple arcade motorcycle game and I have the basic gameplay functioning. The next step is to take the vehicle handling from "working" to "engaging". The bike needs to tilt while turning and slide wide if players take turns at high speeds. To achieve both of these things, I want to measure the lateral speed (basically: how fast is it drifting?), but I really don't have the slightest clue of how to do something like that.
Comment
ouch they make it difficult. float driftSpeed = Vector3.Dot(rb.velocity, transform.right); + is drift to right - is drift to left
Best Answer
Answer by YoucefB · Oct 15, 2017 at 01:38 PM
You want to get the velocity relative to the gameObject's local space:
Rigidbody rb;
DriftSpeed = transform.InverseTransformDirection (rb.velocity).x; // if z is the forward direction then x is the drift direction. positive value means drift in the right side and negative the left side.