Vector3 magnitude broken?
I am trying to make a speed limit for a vehicle in my game, but using Vector3.sqrmagnitude or magnitude gives me a slowly increasing number, it doesnt matter if the vehicle is moving slowly, quickly, or not at all. What's going on? I'm using
float speed = GetComponent<Rigidbody>().velocity.magnitude;
Debug.log(speed);
to log my speed.
Comment
Best Answer
Answer by JackTheKreator · Sep 11, 2017 at 06:25 PM
Sort of an answer for anyone stumbling on this. I fixed it by putting the rigidbody into a child of the object and referencing it with GetComponentInChildren(). Not a perfect answer, but a quick fix.
There must be something else. $$anonymous$$ost probably you're getting a different rigidbody. I'm using velocity and Vector3.magnitude with vehicles extensively and haven't noticed any issue with it.