Character Controller moving at different Framrates? [Unsolved]
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 :(
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);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612131751im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I make player attack with LMB if the enemy is within range? 0 Answers
How to make a character Jump given a certain condition 0 Answers
Isometric Movent Issue 0 Answers
Jumping with slight air control while retaining velocity 1 Answer
Character's jumping mechanism stuck into something invisible 1 Answer