Jittery elevator
Hi.
I tried a few things from answers provided elwhere in this forum, but can't seem to get something satisfactory working. I have this elevator that I build. It works fine, except that the movement is jettery going up or down. I think the problem is the interaction between the character controller and the moving plateform. My character is based on the character controller with gravity set in code. The plateform moves using Transform.Translate and a Coroutine with WaitForSeconds. I tried moving with an animation, but same result. I tried making the plateform the parent of the character controller, but still jittery. I tried with / without rigidbody on plateform, same results. I experimented with differeent gravity values, same result. The best result I have is when the plateform is the parent of the controller and I set the gravity of the controller to 0 - but then, but then for some reason the controller doesn't quite follow the parent (there is an offset on the y transform at the end of the animation). Any suggestions on how to remove the jitter OR get the character contoller to follow the plateform parent during animation? Thanks!
Here is the main code to move the plateform.
public void Movement()
{
if (aaa) // this is a check to validate that player is on the plateform
{
moveDirection.x = xAxis;
moveDirection.y = yAxis; // In this case, this is set to 0.1 by the elevator controller. This is a Delta3.
moveDirection.z = zAxis;
StartCoroutine(moveObject());
IEnumerator moveObject()
{
for (float i = 0f; i < moveDuration; i++)
{
moveDelay = Time.deltaTime;
transform.Translate(moveDirection);
yield return new WaitForSeconds(moveDelay);
if (i == moveDuration - 1) elevatorSound.Stop(); // just a sound...
}
}
}
}
Here is a except from the player code that controls gravity (std stuff I adapted from the Unity manual + using new input system). I am not including the whole thing, but hoping this will be enough.
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
Your answer