[SOLVED] Character Controller moving at different Framrates?

Hello Everybody,

i have a problem: my Character controller is moving as it should at 1000FPS but at 60 it jump too height, the camera head bob is not working and he is walking too slow. I already searched in Unity answers, but i dont found a solution. At my cc.Move(move * Time.deltaTime) i alread implemented delta time and it should be the same at all frames but it is not! This is a very serious problem for my game. I know i could do all in FixedUpdate and the Input in Update but it will move jittering in Fixed Update! Please give me a tip to fix that :frowning:

Best Regards, and Thanks in advance!!

T

Heres my Code:

 public CharacterController cc;
 public float walkSpeed;
 public float runSpeed;
 public float crouchSpeed;
 public float gravity;
 public float jumpSpeed;
 public bool canControl;
 //health
 public float health;
 public float Energy;
 public float energyIncrease;
 public float canSurviveFall;
 public float fallDamage;
 public float energyIncreaseTime;
 public float jumpEnergyCost = 200f;
 public float sprintEnergyCost = 1f;
 //HUD
 public Image healthBar;
 public Image energyBar;
 //private variables
 private float X;
 [HideInInspector]
 public float remainingHealth;
 [HideInInspector]
 public float remainingEnergy;
 private bool canRun;
 private bool canJump;
 private float Z;
 private float falledDistance;
 private Vector3 lastPos;
 public Vector3 move = Vector3.zero;
 public int movementState = 0; //0 standing , 1 walking , 2 running , 3 air , 4 crouching
 void Start()
 {
 remainingHealth = health;
 remainingEnergy = Energy;
 canJump = true;
 }
 void Update ()
 {
 if (cc.isGrounded && canControl)
 {
 move = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical"));
 move = transform.TransformDirection(move);
 move *= walkSpeed;
 movementState = 1;
 remainingEnergy += energyIncrease;
 //if the player is walking or crouching it does not cost any energy
 if (Input.GetButton("Sprint") && canRun && remainingEnergy > 1)
 {
 move *= runSpeed;
 remainingEnergy -= sprintEnergyCost;
 movementState = 2;
 }
 if ( Input.GetButtonDown("Jump") && canJump && remainingEnergy > 300)
 {
 move.y += jumpSpeed;
 remainingEnergy -= jumpEnergyCost;
 movementState = 3;
 }
 if (Input.GetButton("Crouch"))
 {
 cc.height = 1;
 move /= crouchSpeed;
 movementState = 4;
 canRun = false;
 }
 else
 {
 cc.height = 2;
 canRun = true;
 }
 }
 healthBar.fillAmount = remainingHealth/ 100;
 energyBar.fillAmount = remainingEnergy / 1000;
 move.y -= gravity;
 cc.Move(move * Time.deltaTime);
 if (remainingHealth < 1)
 {
 remainingHealth = 0;
 Die();
 }
 if (remainingEnergy < 0)
 {
 remainingEnergy = 0;
 }
 if (remainingEnergy > Energy)
 remainingEnergy = Energy;
 if (!cc.isGrounded)
 {
 movementState = 3;
 }
 }
 void Die()
 {
 Destroy(gameObject);
 }

If you’ve already implemented the Time.delta time, you could try setting your rigidbody to Interpolate using interpolate shown below.

It would be helpful to see your CharacterController script as well.

99049-interpolate.png

Try to use a Force for jumping. Maybe you can use a target framerate and optimate it on this when you don’t need 1000 FPS.

time.FixedDeltaTime maybe can help!

Hello everybody,

i sloved it!! I put all my Code in Fixed Update (even the input) and decreased my fixed timestep to 0.006
Withpout vsync i have now 1100 instaed of 1250 fps thats okay! I only let the code with the health bar in the update method.

Thanks everybody!!!