- Home /
Is rigibody velocity frame rate independent?
I have this problem when I'm testing on the editor the the profiler physics have a frame rate of 1000 which is fast so the rigidbody is fast as well but when I tried it on a mobile device the rigidbody quite slow down. So setting rigidbody velocity via user input is bad? Because I couldn't put it on a FixedUpdate since it must trigger on user input.
You CAN manage user's input in Update() and change rigidbody in FIxedUpdate(), or you can manipulate rigidbody in Update() (unrecomended) but use Time.deltaTime as a coeficiant to make it framerate independant.
I couldn't manipulate rigibody in FixedUpdate because I'am manipulating the rigidbody velocity once the user made an input. The is this. void Jump(){ rb.velocity = new Vector3(Random.Range(-1,1), 1, 0).normalized * power); rb.angularVelocity = Vector3.zero; }
Answer by FlaSh-G · May 28, 2018 at 01:45 PM
Your physics shouldn't have 1000 fps, but something around 50, meaning a fixed timestep of 0.02. That's the default value and changing it shouldn't happen without a good reason.
Now, Rigidbody.velocity is just some value that you can change. Nothing really happens when you change it. But when, in the next fixed update step, the physics engine does its work, it will move the all rigidbodies according to their velocities. Since it does that in a pseudo-constant frequency, changing fps should definitely have any influence on physics calculations. And chaning the velocity, at what time whatsoever, can't influence that.
As @misher said, you can watch input wherever you want and still apply it in FixedUpdate. You just need a variable that serves as a flag:
private bool jumped;
private void FixedUpdate()
{
if(jumped)
{
Jump();
jumped = false;
}
}
However, as I explained, the velocity property already serves as this... "container" for changes to be applied in the next physics update.
So, as to why your velocity varies on mobile... do you use Time.deltaTime
somewhere? What other code influenced time, phyiscs in general, or this rigidbody?
Your answer
Follow this Question
Related Questions
Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers
Cannot move and jump with rigid body. 0 Answers
Any way to gracefully detach object with Unity physics? 2 Answers
Rigbody.velocity stopped working and only displays 0 out of nowhere 2 Answers
Moving rigidbody (Player) with addForce or Velocity ? 1 Answer