- Home /
Character Controller Jitter On Platform With Animation
Hey,
many similar questions have been asked but I think never with the combination of a character controller and an animation.
I have a simple first person character and a platform that can move up and down. To move the platform I use animations (and I'd rather not change this because I want to be able to add more complex motions later).
Everything works fine, except for a very noticable camera jitter when moving up. I have tried making the character a child of the platform for the trip and only apply gravity to the character when the platform is moving up. The problem remains.
I don't necessarily need to make the character or the camera move perfectly in sync with the platform - being able to slightly smooth the camera for that duration would probably be enough.
All character movement (including gravity) is obviously calculated using Time.deltaTIme.
This probably happens because you have some kind of camera script that tries to follow your player smoothly and this breaks down in situation where player receives additional translations from physics engine (I'm guessing that animation drives physics here). To solve this I would add platform translation delta to camera position every frame while character is moving with this platform.
Update ()
if( player_moving_on_a_platform )
cameraTransform.position += platform_delta_position;
Or just drop this camera's "smooth follow" code altogether.
The cameras position is not updated through code. It's simply a child of the player GO with the Character Controller. The players position is also never changed directly - only using Charater Controller Move. When using your code instead of having the player be a child of the platform it still jitters. I've noticed that the players local position doesn't stay consistent. It varies from about 1.04 when the platform is standing still to below 1. Maybe that has something to do with it? I don't have much time rn but I'll try keeping the local position more stable using code and post an update
Oh. That is a important information. Ignore what I wrote then.
In general, this quick solution you picked, to just parent main camera to a player controller has this exact shortco$$anonymous$$g of not working well when physics interactions come into picture.
This is because physics engine is kind of a parallel simulation that must update/sync transforms in your scene on it's very own schedule fixed time step
. The problem is: FPS vary every second of the game and this causes the number of physics updates per rendered frame to vary as well. See$$anonymous$$gly harmless but it means that this platform will move your player (with it's camera) a varying distance every frame and that's manifesting itself as an ugly jitter motion.