#Player Movement on a moving rotating platform (ship) jitter

1 messages · Page 1 of 1 (latest)

fresh mason
#

The problem:
Player experiences jitter but only when the ship goes down. (singleplayer)
The video is attached below.

Context:
The ship is dynamic rigidbody.
The player uses character controller.
Code attached below

What I have tried:
Putting ApplyGravity() in LateUpdate()
Applying more downforce when grounded. (Turns out if I apply more, the jitter becomes even worse)
Switching to dynamic rigidbody (Built-in rigidbody gravity works fine but it doesn't suit my project cuz of multiplayer in the future)

Code:

The whole script:
https://paste.mod.gg/ognrfanalksl/0

Useful parts:

  void LateUpdate()
    {
        RotatePlayerCharacter();

        ApplyGravity();
    }

  private void AlignPositionWithShip() 
    { 
        // TODO separate the camera and smooth the Y movement

        Vector3 delta = ship.GetDeltaPosition(); 
        delta.y = 0;
        characterController.Move(delta); 
    }

private void ApplyGravity()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundCheckSphereRadius, groundMask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }
        else if (MovementMode.InWater == currentMovementMode)
        {
            // Reduced gravity effect in water
            velocity.y = 0;
        }
        else
        {
            velocity.y += GRAVITY * Time.deltaTime ;

            characterController.Move(velocity * Time.deltaTime);
        } 
    }

  private void Jump()
    {
        if (isGrounded)
        {
            velocity.y = Mathf.Sqrt(-2f * GRAVITY * jumpHeight);
        }
    }

terse holly
#

For one thing - maybe not related to your primary issue but you should not be multiplying deltaTime into the mouse input for rotating the player

#
        float mouseX = rotationVector.x * mouseSensitivity * Time.deltaTime;
        float mouseY = rotationVector.y * mouseSensitivity * Time.deltaTime;```
#

this is going to cause jittering and inconsistent rotation speed

fresh mason
terse holly
#

No

#

Just get rid of deltaTime like I said

#

it doesn't belong there

fresh mason
#

ok!

terse holly
#

(you will need to adjust your sensitivty down a lot)

fresh mason
#

i see

terse holly
#

in general your approach here involves moving the player and the ship at two different cadences. It might be fundamentally flawed. I'm not sure how CharacterController interacts with rigidbody interpolation exactly

#

But your Rigidbody ship is going to be moving at the FixedUpdate cadence

#

and CharacterController is more or less on the Update cadence. I don't think CharacterController was really designed for this kind of use case and might just be a fundamentally flawed basis for this system

fresh mason
#

das crazy

#

i mean its just very very hard to do math-based wave roaming ship

#

i guess thats the only way now

fresh mason
#

Thank you! I will look into it

#

so with KCC i can keep my physics based ship?

#

since they both work on FixedUpdate