0
\$\begingroup\$

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?

\$\endgroup\$
3
  • \$\begingroup\$ Have you considered adding gravity only when you're not in contact with a ground surface, such as a moving platform? \$\endgroup\$
    – DMGregory
    Mar 24, 2020 at 19:46
  • \$\begingroup\$ @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. \$\endgroup\$
    – Jay
    Mar 24, 2020 at 20:49
  • \$\begingroup\$ Sounds like you should update your question then to reflect your current understanding of the problem. \$\endgroup\$
    – DMGregory
    Mar 24, 2020 at 20:52

1 Answer 1

-1
\$\begingroup\$

Add a Rigidbody and use the gravity there?

\$\endgroup\$
1
  • \$\begingroup\$ Dont know what you mean. I have a Rigidbody but what does it had to do with the character controller? \$\endgroup\$
    – Jay
    Mar 24, 2020 at 19:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .