Jittery Movement
Options
in Fusion
Hello everyone, can anyone help me see what we're doing wrong here? I'm still getting jittery movement on this character, as if both server and clients are fighting to move it. We're following API by the book with minor changes to gameplay:
This is our Input:
And this is how we're doing movement, our Move( ) method.
/// <summary> /// Basic implementation of a character controller's movement function based on an intended direction. /// <param name="direction">Intended movement direction, subject to movement query, acceleration and max speed values.</param> /// </summary> public virtual void Move(Vector3 direction, bool fly, bool ascend, bool descend, Vector3 camRight, Vector3 camForward) { var deltaTime = Runner.DeltaTime; var previousPos = transform.position; var moveVelocity = Velocity; //if(GetComponent<NetworkPlayer>().isPC) //print("player camRight: " + camRight); direction = direction.normalized; if (Runner.IsServer) { //Are we flying? Adjust the isFlying variable if (isFlying && fly) { print("Turn off flying"); isFlying = false; } else if (!isFlying && fly && isFlier) { print("Turn ON flying"); isFlying = true; } } //Horizontal Movement if (!isRunning) { currentSpeed = walkSpeed; if (isFlying) { currentSpeed = flySpeed; } } else { currentSpeed = sprintSpeed; if (isFlying) { currentSpeed = sprintFlySpeed; } } //Vertical Movement //I'm NOT Flying if (!isFlying) { moveVelocity.y += gravity * deltaTime; //print("Not flying here"); } //I'm flying! else { float gravityForce = 50f; moveVelocity.y = gravityForce * direction.y * deltaTime; } var horizontalVel = default(Vector3); horizontalVel.x = moveVelocity.x; horizontalVel.z = moveVelocity.z; if (direction == default) { horizontalVel = Vector3.Lerp(horizontalVel, default, braking * deltaTime); } else { Vector3 cameraDirection = direction.x * camRight + direction.z * camForward; //horizontalVel = Vector3.ClampMagnitude(horizontalVel + direction * acceleration * deltaTime, currentSpeed); horizontalVel = Vector3.ClampMagnitude(horizontalVel + cameraDirection * acceleration * deltaTime, currentSpeed); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(camForward), rotationSpeed * deltaTime); } moveVelocity.x = horizontalVel.x; moveVelocity.z = horizontalVel.z; // calculate camera relative direction to move: // moveVelocity = moveVelocity.z * m_CamForward + moveVelocity.x * m_Cam.right; Controller.Move(moveVelocity * deltaTime); Velocity = (transform.position - previousPos) * Runner.Simulation.Config.TickRate; AnimationHandler(moveVelocity, isFlying, direction.x); CheckGroundStatus(); if (!IsGrounded) FallTimer(); else { fallTimer = fallTimerReset; } }
0