How to see if a character is moving forward relative to it's rotation?

I would like to see if a character is moving forward relative to it’s location in the world, and if it is then increase a variable.

Basically, if the ‘w’ key is pressed then increase the variable. The problem is, that I’m doing this in the event graph in my character’s animation blueprint.

Any way to do this simply?

Some more info:

I have a blendspace with 2 axis: x-speed and y-speed.
When the w key is pressed, I want to increase the x-speed,
and pressing the s key would do the opposite.
Same thing goes for y-speed, except d and a as appose to w and s respectively.

Changing these variables, in turn should change the animation it is playing…

have you looked at the thirdperson blueprint tutorials?

if not you should but one thing you should look at in your character blueprint is MOVEFORWARD and MOVERIGHT.

I think what DJMidKnight is trying to say is that the Third Person Blueprint Tutorial does exactly what you are trying to do in their videos. Specifically, this one.

Edit:

That video I linked is the Blend Spaces one. He shows you how to get and assign the values for the blend space a few videos later but I recommend you start with the video I linked.

Yes I’ve followed them all. The problem is that in those there is only one variable which is speed. For mine I have 2, and they all go into the negatives. For the tutorial the guy just assign speed to the length of the vector your moving wether or not you’re moving forward left or right. For me I need to know if the chatter us moving forward or backward relative to himself.

I’ve replied to the other comment why this does not work for me, anything else?

Do you use a CharacterMovementComponent on your Character?

i’m not exactly sure what that is, but here is what my character blueprint looks like: How to see if a character is moving forward relative to it's rotation? - Character & Animation - Epic Developer Community Forums

The actor is a character… And from the little research I did, it seems that I am…

I will be able to send you a link to what my animation blueprint looks like later today.

Well, the way this usually works is you reference your Characters Animation Blueprint in your character blueprint and assign values there. You could use your characters CharacterMovementComponent Velocity value and get the X and Y movement out of that. Then you just pass it to the variable in your Animation Blueprint through the reference.

I can make images when I get home if you still don’t understand.

That would be great!

Sounds like you want to compare the result of GetActorForwardVector and CharacterMovement->GetVelocity. If the dot product of the velocity and the actor forward vector are greater than some threshold, you are moving forward.

For background, the dot product of two unit (normalized) vectors is equal to the cosine of the angle between them. So if they point exactly the same direction, the dot product equals 1, opposite -1, perpendicular 0. I would suggest testing within a tolerance, like if the dot product is > 0.7 (about 45 degrees), you are moving “forward” within 45 degrees or less.

My blendspace looks like this:

Where positive charDirection is right, and positive charSpeed is forward.

This is what my animation blueprint event graph currently looks like:

I’m not sure what you mean by “how much”. The angle/dot product approach tells you how close you are to forward. You can also use the Velocity magnitude compared to the max speed, or a combination of that and the angle.

Sorry about that. This works for forward and backward, but how would I do this for left and right? (As in change charDirection?)

You can do a similar test with GetActorRightVector maybe.

Forward = (ForwardVector dot Normalize(Velocity));
Right = (RightVector dot Normalize(Velocity));

An alternative would be:

angle = ACos(ForwardVector dot Normalize(Velocity));
Forward = Cos(angle)
Right = Sin(angle)

Hopefully I’m helping, I don’t know much about animation BPs :wink:

(Edit: Also you might want to scale by Velocity.Size() / MaxSpeed or something!)

Looks like you got it sorted, I was about to post the images. Oh well =)

Glad you got it working!

Thanks you helped a ton!

May I ask what you work as for epic?

Programmer/Engineer

Thanks a lot for that Zak! i was able to implement proper dust particles for my Vehicle’s movement this way, much appreciated.