x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[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. :)

Product Version: Not Selected
Tags:
more ▼

asked Mar 11 '14 at 02:32 AM in C++ Programming

avatar image

ue4-archive ♦♦ STAFF
49.9k 3667 1996 9121

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

"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

more ▼

answered Mar 11 '14 at 02:32 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3667 1996 9121

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

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. ;)

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. :) 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.

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

"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 :)

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 :)

Are you using a blendspace for the walking animations?

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

Well, they aren't moving separately so long as the character moves in the same direction as it spawned. ;) 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.

This is what it looks like

citizenbp.png (159.6 kB)
avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

"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?

:)

Rama

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

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?

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

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

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

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).

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

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

Well it moves my characters just fine :)

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 :)

Rama

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:32 AM

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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Mar 11 '14 at 02:32 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3667 1996 9121

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question