This site uses strictly necessary cookies. More Information

X- 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

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

2d game - looking toward velocity for rigidbody player 1 Answer

Comparing rigidbody speeds 1 Answer

How to keep velocity and add onto it from any rotation. 1 Answer

Speed based on distance 1 Answer

Rotating wrong 0 Answers