# Combining two vector lengths into one to calculate speed

**URL:** <https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367>\
**Category:** Blueprint\
**Tags:** unreal-engine, speed, Blueprint, question, vectors\
**Created:** [May 1, 2017, 11:21am UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367 "2017-05-01T11:21:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [May 1, 2017, 11:21am UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/1 "2017-05-01T11:21:42Z")

</div>

What I am trying to do is combine two vector lengths into one, and then using the vector length of that to set my speed variable. I am using Root Motion, so the get velocity function won’t help me here.

This is what I was able to come up with so far, but I feel there may be a better way to do this since my Speed variable isn’t a 1 across all angles of movement (in other words, my speed going left or right will be a 1, going front-left will be 1.012 something, and going back-right my speed will be .88 something).

 ![136302-nww4rim+-+imgur.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/0/1d06ecfa34a0ea840ce2e89a11f13e8bcb3955a4.png)

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 11:34am UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/2 "2017-05-01T11:34:44Z")

</div>

Basically right way to calculate your speed is get the difference of current location and location at previous frame. Then divide this by delta time between frames.

If you need more information, ask about it)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f77a82de](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f77a82de](https://forums.unrealengine.com/u/anonymous_user_f77a82de)\
**Post date:** [May 1, 2017, 11:36am UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/3 "2017-05-01T11:36:54Z")

</div>

![136289-myproject2+-+unreal+editor+5_1_2017+4_41_43+am.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/4/d/24d41799cbb790aca2f432cf92d736440b851ca7.png)

Hey There is a function called Normalize. I Seen it before but don’t fully understand it’s use. Are you able to explain so in the future I understand. “I know it has something to do with speed and know other ways… but a explanation of this will be nice”

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 11:45am UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/4 "2017-05-01T11:45:56Z")

</div>

You’d better create a brand new question in order not to increase the entropy of the universe)

And after that I’ll be happy to answer)

---

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [May 1, 2017, 12:03pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/5 "2017-05-01T12:03:14Z")

</div>

You were on the right track.  
Simply add both vectors (the ones multiplied by Right/Forward) and divide by two. Then normalize.

---

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [May 1, 2017, 12:12pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/6 "2017-05-01T12:12:37Z")

</div>

Ah okay. So I just implemented that without the normalize function because I want the decimals in order to drive a walk/jog blendspace. Normalizing it just sets it to 1, so I never get the walk animation. This method gives me the same input as the method I tried in the picture. So diagonal movements aren’t set to 1 but are set somewhere between .86-.99 depending on the angle of movement.

Also, I didn’t divide by two because I would get .5 as my max speed instead of 1.

---

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [May 1, 2017, 12:17pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/7 "2017-05-01T12:17:06Z")

</div>

So I tried your suggestion, but when debugging I just get a really huge number on my print screen. So by default I never get that walking animation that I am looking for.

 ![136308-iimwjly+-+imgur.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/0/960a91014dd947128cf230404e5c1e617a3d9e38.jpeg)

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 12:21pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/8 "2017-05-01T12:21:16Z")

</div>

Don’t divide, use only difference or you can even normalize vector to 0-1. It depends on where you use your speed.

---

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [May 1, 2017, 12:40pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/9 "2017-05-01T12:40:35Z")

</div>

Not dividing still gives me a big number. Looking at my BP, does my math look correct? On Begin Play I set Old Location to Actor Location, then continuously update Old Location with the difference between Old and New Location…as depicted in the picture. And normalizing it sets it to one, which doesn’t allow me to run my walking animations

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 12:52pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/10 "2017-05-01T12:52:41Z")

</div>

I don’t know what value do you expect to see in the end of the day but this is literally normalized speed vector.

 ![136313-2017-05-01_19-51-01.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/2/eb2038086c629398a4ab9e865848023dbc8bbb2b.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f77a82de](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f77a82de](https://forums.unrealengine.com/u/anonymous_user_f77a82de)\
**Post date:** [May 1, 2017, 1:28pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/11 "2017-05-01T13:28:45Z")

</div>

Ahh you’re looking for a math solution… well idk. Think about what calculations you may use and go ahead

---

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [May 1, 2017, 3:02pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/12 "2017-05-01T15:02:21Z")

</div>

Alright, so after some thinking this is how I solved it. This gives me a max value of 1 all the way around when the thumbstick is fully pressed, while still returning decimals if the thumbstick isn’t full pressed. This allows me to play both walk/jog animations within one blendspace. Thank you for all of the suggestions guys.

 ![136310-mbau4xn+-+imgur.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/3/cc3cf8b0466eb5c78bbfe3011f7446a517d5d740.png)

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [May 1, 2017, 5:14pm UTC](https://forums.unrealengine.com/t/combining-two-vector-lengths-into-one-to-calculate-speed/392367/13 "2017-05-01T17:14:41Z")

</div>

So bad we couldn’t help you with such a simple question…
