- Home /
Character Controller Is Lagging Behind Enemy
I'm working on a game with some basic zombie AI and everything seems to be working except for the fact that the character controller seems to be lagging behind the enemy as he moves which makes him sort of jump backwards every so often to correct himself and I'm not sure how to fix it. This also causes the enemy to seem to grow in my First Person camera view but not the other scene camera.
Here is a short video I recorded so you can better understand what I am talking about:
http://www.youtube.com/watch?v=4YFjX_5fUTo
If you'd like to see the zombie AI code it can be viewed here and the other code would be straight from the Unity FPS tutorial pretty much.
Thanks for your help, I really appreciate it!
Answer by Nate3d · Aug 11, 2011 at 03:48 PM
Find your character in the Hierarchy, and look through its child objects. There should be something called "Root" or a similar name for the top-level joint in the skeleton hierarchy. I haven't worked with Mixamo animations so I don't know their naming convention.
Select the root joint and then open the Animation View (Ctrl-6). In the top left corner just under the record and play buttons, you'll see two pull-down menus where you can select the different animations applied to that character. You'll need to dig through this and find the walking-forward animation. Once you have it selected, look for "Transform", click the triangle next to it if it isn't expanded already, and select Position.x, Position.y, and Position.z.
Press the F key to center the animation data in the graph to the right. You should see one animation curve gradually increasing (or decreasing) in value, and doesn't return to its original value at the last frame. It will probably be Position.z. Select all the keyframes in that animation curve except for the very first one, and delete them. That should stop the character from animating itself off of your character controller.
(If you don't see an animation curve for the root joint that fits the criteria, it may mean there's another joint in the skeleton under the root that's translating forward- Perhaps a joint called "pelvis" or "hips.")
Here's the Animation View reference: http://unity3d.com/support/documentation/Components/animeditor-UsingAnimationEditor.html
Hope this helps!
Aweomse that fixed the issue where he was jumping ahead of the character controller! However, he still seems to grow as he draws closer to me and our player scales are the same. Do you happen to have a workaround for this as well? Thanks again!
Sorry to bother you again Nate3d, I just can't seem to fix this last problem. The mob (as it comes closer to me) lifts slightly off of the ground (slowly getting higher and higher). I'm assu$$anonymous$$g this is due to animation translations again and it slowly moves him up, but they rest of the animations seem to match up.
So I was just wondering if you had any last thoughts! Thanks :)
Answer by Nate3d · Aug 11, 2011 at 01:01 AM
Looks like he has forward translation keyframes on his skeleton root during the walking-forward animation. Every time the animation loops, he pops back to the original local position.
Is there any way to remove these keyframes from the animation? I got the animation from maximo in the Unity Assets store, if that's any help.
If this isn't possible, can I alter my script (mentioned above) to account for this extra forward motion?