简体   繁体   中英

Unreal 4 C++ Actor Movement

I have data for an actors movement which is being read in from a file at the start of the game. The data that gets read in contains Vector positions where the Actor should move to next. I currently have the Actor moving from Position to Position no problem... until I start to add animation to a Skeletal Mesh attached to the Actor.

My problem: How can I found out the velocity to work out which animation to play idle, walk, jog and running? It currently doesnt have a velocity as i am lerping the position:

SetActorLocation(FMath::Lerp(GetActorLocation(), newPos, 0.01));

Any thoughts on how to set the right animation based on distance travel and speed?

Should I move my Actors movement to Character so I can use AddMovementInput to get velocity. Then, If i go down that route, how to I say:

Move this character from my current position, to my next position in X amount of time giving the character the correct velocity to use in the animation selection.

Can you normalize the difference between the two vector lengths (GetWorldLocation) and use the abs(floating point) result as the X variable to put into 1D Blend Space to do idle, walk, jog, run in your Animation BP? Also be sure to account for an "acceptance radius" or else once it gets to location it won't quite get it and keep turning quickly.

Not sure why you're Lerping from Vector to Vector. I would've personally used (MoveToActor or MoveToLocation):

AMyPawn->MoveToActor(AMyActor, 90.f,true,true,false,0,true);

So much cleaner! Also MoveToLocation, using BT/BB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM