0
votes

I have a line that is applying force to the player. The force is applied in an Update() while the player is in the Roll animation state.

        if (anim.GetBool("isRolling") == true && anim.GetBool("IsGrounded") == true && canRoll == false)
    {
        rb.AddForce(transform.forward * rollLength, ForceMode.Force);
    }

I am targeting two devices, one with high framerate and one with low framerate. On the one with low (30 fps) framerate, it works fine, but on the high framerate (in the 100s) the player goes too far too fast. I have read that Time.deltaTime will divide the force, which doesn't help me. What can I do to fix this issue?

2
Don't you want to move it to FixedUpdate ? - Charleh
As well as you are adding force in every frame therefore the force will not be constant - BugFinder

2 Answers

0
votes

Addforce doesn't add Force in physical sense as much as it adds energy: you should control amount and frequency byt Time.deltaTime which makes single call time-dependent, but also you should keep in mind that FixedUpdate exists - it works like a classic Update but it's guaranteed to have constant time in between each calls (equal Time.fixedDeltaTime). Generally speaking if you manipulate phisics in each frame you most likely want to use FixedUpdate instead of Update

But honestly I would considered if addForce is good idea for a rolling mechanic in the first place: I feel like it would be better idea to use Rigidbody.velocity or Rigidbody.Move()

0
votes
  1. As said above: "AddForce" doesn't really adds force, but energy instead so you should scale it using Time.deltaTime

  2. When doing physical calculations in unity it is recomended to do them inside FixedUpdate, as it is guaranteed to have constant rate of activation which allows you to avoid certain problems that are often for physics with even small framerate fluctuation and correct usage of Time.deltaTime