# Combining two vector lengths into one to calculate speed

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).

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.

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”

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)

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

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.

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.

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

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

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

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

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.