Switching between idle and walking animations while using SetActorLocation()

Hi, I need to move MyActor forward a certain distance in 1 second, and switch its animation from idle to walking. I’ve done the moving part using SetActorLocation() and LERP() to get a smooth movement, but now I have issues animating the actor. In this tutorial, a blend space is used to animate the character based on its velocity. However, since I use SetActorLocation() instead of simulating physics, that method doesn’t seem to work in my case.

What should I do? Do I change the way I perform the movement of the character, or do I animate the character using a different method than in the tutorial?

Some extra context: I’m making a program where a 3D character executes commands such as “move forward” or “turn left” that are given to it in a .txt file

You will end up having issues if you take this approach, the first one that comes to mind is that you will have foot sliding, but if you still really want to try this out do the following: first create a variable to hold a fake movement velocity, let’s call it “fakeVel” on the player character, Let’s assume that your animation blendspace blends the animation between 0 and 2, 0 being Idle, 1 walk and 2 run. Now go to the animation blueprint pf your character, go inside your locomotion state, into the section where you setup your animation blending for the walk and use both the actual velocity and the fake movement velocity var (“fakeVel”) you created on your character to update this blendspace (use an OR statement), you will have to create a variable on the anim event graph (another “fakeVel”) and update the values with the “fakeVel” from the character on the event tick for this to work.

Now that you have this setup you can update the values on the “fakeVel” whenever you call the LERP(), use 0, 1 or 2 to specify how you want the blend space to animate your character.

All of this should be possible using “InPlace” animations (I mean no root motion) because root motion animations will make your character move with the animation and this will really mess up things in your particular case. Now all of that being said, I think that you should move your character in a different way, using a SetActorLocation() and LERP() is definitely not a natural way to move a character, you should do this using input from the player instead.

I hope I made this simple enough to understand, I really hope this helps.

If you want a quick fix, you can try to calculate the velocity by yourself. After you have moved your actor, subtract the old position from the new position, to get the delta he has just moved. Then divide it by the DeltaSeconds and you have the velocity. But chances are this could be a bit inaccurate, especially at high FPS = small DeltaSeconds. But perhaps it is sufficient for animation.

Thanks! One thing I don’t get though, how do I pass the value of fakeVel from my C++ code to the anim event graph? Do I do that in the C++ code? If so, how do I access the anim event graph fakeVel?

Nevermind, I gave up on blending Idle and Walk. Instead I set the animation mode to single node and I play Walk and Idle separately. It doesn’t look amazing, but it’s good enough for the purposes of my project.

Check this link and also my respond. I had same issue and now, it works fine…