Move in place motion a few steps each button press

Hi all,

I’m looking for the simplest way to move character a few steps the he makes in an animation. Inplace boxing attack.

He steps forward around a metre in the 1 second clip. I’ve tried Rigidbody.moveposition, tried addforce and transform translate but its difficult finding the correct amount. He either moves too far, teleports at the beginning of the animation or stays in place.

Is there any tips or trick to do this?

Thanks

Andy

Have you looked into generating root motion for the character? There is a video tutorial in the learn section on how that is done.
Beyond that - the best process is to create the animation you want externally in a 3D app. This might not be what you want - but it is the best process regardless.

1 Like

I already have the animations. The character controller is almost done, he moves, rotates does some specific functions for creating a nest, eating, interacting etc… So don’t really want to change the controller to root.

I just have a couple of attacks that don’t really work properly. Is it really tricky to create a movement for each animation play that will move the char a set distance like two strides? I know it is for me at the moment lol :slight_smile: I just thought I was missing something simple.

thanks @theANMATOR2b , I took another look at the scripting root motion page and I have made some headway.

The character is moving quite believable now (curves are quite beautiful) I got one slight issue to crack as when I move the player the motion’s rotation seems to change.

Originally the animation moves the player forward but after I have controlled the player the animation has swung around and it is moving him the wrong way. I don’t suppose you have any idea how to correct that?

Thanks again for your help.

So I think I worked out the issue. The unity docs scripting tutorial does not account for the rotation of the player so as soon as the player changes rotation the motion is not the correct direction. Unity - Manual: Tutorial: Scripting Root Motion for "in-place" humanoid animations

Can any quaternion experts help how to account for it in this function?

Vector3 newPos = gorillaMeshTransPos;           
            newPos.z += anim.GetFloat("RootMotion") * Time.deltaTime;
            transform.position = newPos;

I’m not a coder so I can’t assist beyond suggesting where to look for help. I’m glad your making progress. Please update with your final solution once you find it.

1 Like

The solution was so simple it hurts…

(transform.forward just needed to be added to my script.) works as intended now.

1 Like