Custom Pawn Velocity Always Zero
I'm messing around with pawn movement, so I followed the wiki and added a UPawnMovementComponent to a custom Pawn class. It moves around the level nicely, but every time I attempt to get it's direction or velocity the result is always zero.
Calling the pawn's GetVelocity() and taking the length of the vector returns zero. Even if I set a variable on the class in c++ and grab it via blueprints, it's zero.
So the pawns movement code looks like:
This works great, it moves around nicely, but GetVelocity always returns zero and I cannot figure out why. It's moving the RootComponent (which is a capsule), is it because the pawn isn't moving, but the capsule is?
Here is the constructor of the Pawn:
Here is the movement class, for reference:
Just to clarify, the issue is, when you want to find out the speed of the pawn, for animations or the like, it never returns a correct speed, so in blueprints when you do Pawn -> GetVelocity() -> Get Vector Length() it's zero. So I think I messed up somewhere but where I don't know.
asked May 08 '17 at 02:15 AM in C++ Programming
This is because the movement components are required to set the velocity by themselves. If you take a look into
answered May 08 '17 at 07:09 AM
This is how APawn returns the velocity
It checks if the root component is simulating physics, if it is, it returns the component velocity. If it doesn't, it checks for the MovementComponent and returns the MovementComponents velocity.
So I guess that your MovementComponent isn't setting the Velocity variable.
Follow this question
Once you sign in you will be able to subscribe for any updates here