# Gravity CharacterController on moving platform

I have a third person character witha character controller. In the C# Player script I set the move direction like this which works pretty nice to simulate gravity

private Vector3 _moveDirection = Vector3.zero;

private float Gravity = 20.0f;

void Update()
{
// ....
_moveDirection.y -= Gravity * Time.deltaTime;

_characterController.Move(_moveDirection * Time.deltaTime + mExternalMovement);
}


The mExternalMovement (also Vector3) I set when the player is on a platform that moves. This works as well for platforms the move e.g. from left to right. But when I use the same for platforms that move up and down the player is like trembling- because of the gravity that is always set for the y movement.

But I have to set the gravity as well when standing on the platform.... any ideas?

• Have you considered adding gravity only when you're not in contact with a ground surface, such as a moving platform? – DMGregory Mar 24 '20 at 19:46
• @DMGregory: Yes, but it hs not effect and it seems like that it isnet the gravity. It is doing this in one step: _characterController.Move(_moveDirection * Time.deltaTime + mExternalMovement); But when I move this _characterController.Move(mExternalMovement) to LateUpdate and keep _characterController.Move(_moveDirection * Time.deltaTime in Update it works smoothly. – Jay Mar 24 '20 at 20:49
• Sounds like you should update your question then to reflect your current understanding of the problem. – DMGregory Mar 24 '20 at 20:52

## 1 Answer

Add a Rigidbody and use the gravity there?

• Dont know what you mean. I have a Rigidbody but what does it had to do with the character controller? – Jay Mar 24 '20 at 19:24