- Home /
How can I quickly calculate Land Speed from a Vector3?
If I know how fast the object is moving in 3space via a Vector3 magnitude of meters per second, what is the most efficient means of converting that Vector3 to landspeed, assuming that "land" is a flat plane on the XZ?
My current calculation is:
// pseudo: landSpeed = ((Vector3.x^2) + (Vector3.z^2))^0.5;
var landspeed = Mathf.Sqrt(Mathf.Pow(g_AvatarRB.velocity.x,2) + Mathf.Pow(g_AvatarRB.velocity.z,2));
My studies of quaternions and vector math leads me to believe that there is a more efficient way, avoiding square root calculations. True? And if so, what is it? Thanks in advance.
I've also looked here, but I don't understand it: http://docs.unity3d.com/410/Documentation/Manual/AmountVectorMagnitudeInAnotherDirection.html
Answer by LSPressWorks · Apr 15, 2015 at 01:42 AM
why not start from velocity.magnitude
? gotcha. So dot would atke the raw velocity.normalized as first argument(or faster magnitude)and return the portion of that velo from forward or x or whatever. So
Landsped =V.dot(raw velo,dir you wamt)
Or
Landspeed = Vector3.Dot(car.rigidbody.velocity.normalized,car.transform.foward);
Sorry, on phone, cant format it.
that's the thing; I don't want the speed along "direction i want", i.e. the relative forward vector of the player. I just want the speed in terms of a total vector magnitude on the XZ plane. Even if its lateral, strafe etc. in regards to the player rigidbody orientation.
In otherwords, the speed of the players shadow on the ground at high noon.
Your answer
Follow this Question
Related Questions
Comparing rigidbody speeds 1 Answer
2d game - looking toward velocity for rigidbody player 1 Answer
Speed after Vector3.Reflect Decreases,Speed of ball after Vector3.Reflect decreases 0 Answers
Error when trying to implement JumpPad/GravityPad type effect on CharacterController (Solved) 1 Answer
Velocity value changes way to drastically when position quickly changes 0 Answers