Hello everybody,
im have the same problem since weeks: Getting my player movement frame independent!
I cant do it in Fixed Update because it will move Jittering. Im using a Character Controller. So i create
a custom Method with Invoke Repeating. I think its frame idependend but the problem is that at 1000 fps the player has less gravity then at 60. How is that possible!!! Heres my custum method:
void Awake()
{
remainingHealth = Health;
remainingEnergy = Energy;
remainingArmor = Armor;
canJump = true;
InvokeRepeating("TimedUpdate", 0, 0.1f);
InvokeRepeating("Move", 0, 0.001f); //Here it is calling my move method every 0.001 seconds.
}
//Thats my move method wich is called every 0.001 seconds. Everything is time base how can it be that at 200 fps it can jump heigher than at 60. This problem is makeing me crazy!!!
void Move()
{
if (!isDrone)
{
if (cc.isGrounded && canControl)
{
move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
move = transform.TransformDirection(move);
remainingEnergy += energyIncrease;
move *= walkSpeed;
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;
remainingEnergy -= sprintEnergyCost;
movementState = 2;
step = 0.3f;
movementInfo.text = "Movement state: Sprinting";
}
if (Input.GetButtonDown("Jump") && canJump && remainingEnergy > jumpEnergyCost)
{
move.y += jumpSpeed;
remainingEnergy -= jumpEnergyCost;
movementState = 3;
footstepsAudio.clip = Jump;
footstepsAudio.Play();
movementInfo.text = "Movement state: Jumping";
}
if (Input.GetButton("Crouch"))
{
cc.height = 1f;
move /= crouchSpeed;
movementState = 4;
step = 0.8f;
canRun = false;
movementInfo.text = "Movement state: Crouching";
}
else
{
cc.height = 2;
canRun = true;
}
}
}
move.y -= gravity;
cc.Move(move);
}
Thanks in advance and please help!!!
Regards,
T