I’m sure it’s a update vs fixedupdate problem, but I cant figure out why.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float walkSpeed, runSpeed, crawlSpeed, airAcceleration, groundAcceleration, differentialAcceleration, differential, currentSpeed, targetSpeed;
PlayerState playerState;
Rigidbody myRigidbody;
bool isFacingRight;
// Start is called before the first frame update
void Start()
{
isFacingRight = true;
myRigidbody = GetComponent<Rigidbody>();
playerState = GetComponent<PlayerState>();
}
private void Update()
{
targetSpeed = Input.GetAxis("XMovement");
if (playerState.isCouching) targetSpeed = targetSpeed * crawlSpeed;
if (!playerState.isCouching && !playerState.isRunning) targetSpeed = targetSpeed * walkSpeed;
if (!playerState.isCouching && playerState.isRunning) targetSpeed = targetSpeed * runSpeed;
}
// Update is called once per frame
void FixedUpdate()
{
currentSpeed = targetSpeed;
Vector3 applyMovement = new Vector3(currentSpeed, 0, 0);
applyMovement = applyMovement * Time.fixedDeltaTime;
applyMovement += myRigidbody.position;
myRigidbody.MovePosition(applyMovement);
}
}
I’ve tried moving the inputs to the fixed update, but it still jitters.
EDIT: It seems to have issues in certain areas, not everywhere. From 0 to 8 on the x plane it jitters, and everything after is smooth.