Hello Everybody,
i hvae my player script and i know that time.delta time makes code lines frame - independent. So my character should move frame independent. I Multiple all movement lines with * Time.delta time but it doesn work!!
Heres my code:
void Update()
{
if (!isDrone)
{
if (cc.isGrounded && canControl)
{
move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
move = transform.TransformDirection(move);
remainingEnergy += energyIncrease;
move *= walkSpeed * Time.deltaTime;
movementState = 0;
movementInfo.text = "Movement state: Standing";
//if the player is walking or crouching it does not cost any energy
if (move.x != 0 && move.z != 0)
{
movementState = 1;
step = 0.5f;
movementInfo.text = "Movement state: Walking";
}
if (Input.GetButton("Sprint") && canRun && remainingEnergy > sprintEnergyCost)
{
move *= runSpeed * Time.deltaTime;
remainingEnergy -= sprintEnergyCost;
movementState = 2;
step = 0.3f;
movementInfo.text = "Movement state: Sprinting";
}
if (Input.GetButtonDown("Jump") && canJump && remainingEnergy > jumpEnergyCost)
{
move.y += jumpSpeed * Time.deltaTime;
remainingEnergy -= jumpEnergyCost;
movementState = 3;
footstepsAudio.clip = Jump;
footstepsAudio.Play();
movementInfo.text = "Movement state: Jumping";
}
if (Input.GetButton("Crouch"))
{
cc.height = 1f;
move /= crouchSpeed * Time.deltaTime;
movementState = 4;
step = 0.8f;
canRun = false;
movementInfo.text = "Movement state: Crouching";
}
else
{
cc.height = 2;
canRun = true;
}
}
}
move.y -= gravity * Time.deltaTime;
cc.Move(move * Time.deltaTime);