[Question] Moving animated characters around with physics and driving their animations

I recently asked a question about CharacterMovement but I think I’m going to ask a more pertinent question here - it sounds like the way I was moving characters wasn’t the way Epic designed their systems.

I have some characters that have a physics mesh and a “walk” animation. I currently have them moving around and animating but the direction that the animation follows is (apparently) independent to the rotation of the actor itself - the legs always point in the direction the actor first moves in and never change from that (although the non-animated parts of the actor rotate correctly).

Anyway, these characters are meant to walk inside “tunnels” that are spawned dynamically as part of the gameplay. Because of this, it doesn’t seem like using the navigation system is the right choice. Instead I was calculating the path to follow and driving the CharacterMovement component directly. This has led to multiple bugs - so I’d like to ask what I should be doing to do something like this?

Should I attach some sort of PlayerController to the actor and drive that rather than interacting with the CharacterMovement component itself? Or should interacting with the CharacterMovement component work and I’ve just found some interesting bugs? I’d like to know what I’m meant to do as opposed to what I supposed. :slight_smile:

“I have some characters that have a physics mesh and a “walk” animation”

Can you explain what you mean by Physics Mesh?

Do your characters use their SkeletalMeshComponent called Mesh ?

Or do you have some custom component?

What defines this component as “physics” mesh ?

Why cant you just use AActor::SetActorRotation ?

Rama

The physics mesh is what causes actors to detect collision - in my case it’s a simple capsule. I don’t think it’s relevant to my question, I just wanted to describe everything in case it turns out that I was wrong. :wink:

I’ve actually tried this with the example character from the TopDown code sample - so it’s definitely something related to how I’m using the engine rather than it being the asset itself.

Yes, my characters have a SkeletalMeshComponent. :slight_smile: I do call AActor::SetActorRotation() - but, for me, that’s just rotating the upper part of the body. The legs (which are animated and driven by the CharacterMovement component) are pointing in the wrong direction - they’re apparently ignoring the actor rotation.

“but, for me, that’s just rotating the upper part of the body. The legs (which are animated and driven by the CharacterMovement component)”

I cant comprehend how the legs and the upper body could be moving separately :slight_smile:

You are not using any skeletal controllers?

your upperbody and legs are not separate meshes?

If it is all one single Skeletal Mesh and the upper body is moving correctly…

There must be more to this setup of yours than that :slight_smile:

Are you using a blendspace for the walking animations?

Well, they aren’t moving separately so long as the character moves in the same direction as it spawned. :wink: Once the direction changes, the legs continue to point in one direction and the upper body points in the direction I passed in using SetActorRotation().

As I say, this is also happening with the “Hero” mesh taken from the TopDown code sample - everything is one mesh.

I’d love to know what I’m doing wrong - but I also suspect most people move characters around using controllers and my asset doesn’t have one at all.

“but I also suspect most people move characters around using controllers and my asset doesn’t have one at all.”

I set the rotation of characters in my game, including ones I’ve imported myself, using SetActorRotation() and I’ve never had this issue

I’ve imported and set up at least 4 different characters without ever encountering this issue with setting a character’s rotation.

None of my AI characters use an aicontroller, I do everything within the Character class directly

#Body Slot

Does your Character’s Anim Instance have an upper / Full body slot?

just as a test to see if we are in right ballpark

could you try temporarily disabling the Upper Body Slot

and only using the full body slot?

:slight_smile:

Rama

Well, it turns out that part of the problem was with the HeroTPP_Vim animation blueprint that I shamelessly stole from the TopDown code sample. For whatever reason the “Setting Direction” block was causing the upper body to point in a different direction to the actor rotation - even though the velocity and the actor rotation should have been the same direction in any case.

Still, it seems like what we’re doing is wrong here because… well, here’s some code to demonstrate what I mean:

		FVector current_location = GetActorLocation();

		FVector direction = destination - current_location;
		direction.Normalize();

		FRotator rotation = direction.Rotation();
		SetActorRotation( rotation );

		FVector velocity = direction * MovementSpeed;

		CharacterMovement->MoveSmooth( velocity, DeltaTime );
		CharacterMovement->CalcVelocity( DeltaTime, 0.f, false, false );

So the actor’s rotation and the actor’s velocity should be the same direction. And yes, when I call CharacterMovement->MoveSmooth() then the characters do move and rotate correctly. They just don’t animate until I also call CharacterMovement->CalcVelocity(). That just seems like something I probably shouldn’t have to do - and that’s why I’m asking whether I’m doing something wrong?

#Simplifying

You can simplify this

FVector velocity = direction * MovementSpeed;
CharacterMovement->MoveSmooth( velocity, DeltaTime );
CharacterMovement->CalcVelocity( DeltaTime, 0.f, false, false );

by doing this:

CharacterMovement->Velocity += direction * MovementSpeed;

Velocity is part of movementcomponent

you should not make any variables that are similar to that in spelling, as it is likely to confuse you or even shadow the main class variable Velocity. (if you made another var called Velocity)

#Using Velocity +=

I use Velocity += to create custom character movements easily for both client and Server and

  • it replicates
  • it affects animations
  • it’s eaaaasy

So let me know if this revised method helps

Rama

No. That just affects the velocity (which means the movement animation plays) but doesn’t move the character - and it also ignores the framerate too (you’d have to multiply the total by the DeltaTime to take that into account).

"That just affects the velocity (which means the movement animation plays) but doesn’t move the character "

Well it moves my characters just fine :slight_smile:

It seems there’s something fundamentally unusual about your current setup

To get perspective on all this

I recommend starting a new third Person Project,

to give yourself a fresh look at all this

and try moving a character around, without a controller, using SetActorLocation, SetActorRotation, and CharacterMovement->Velocity+= some relatively large amoutn.

All of that is working great for me :slight_smile:

Rama

Hi Neil,

This issue seems to be related to your particular character setup, and is beyond the scope of the support staff to troubleshoot. You appear to be making good progress with debugging the issue, and along with Rama’s suggestion we recommend that you look at some of the provided character examples to see some functional approaches for character setup.

Cheers and happy developing!

This is fixed …

We found that this was due to the animation blueprint (HeroTPP_Vim) – specifically, the “Setting Direction” block in the lower-right part of that animation blueprint. We basically just disabled that whole block to force the character’s legs to be oriented the same way as the character itself, and that fixed it.