- Home /
climb speed changes drastically when game window is not maximized
when im testing my game in fullscreen, the climb speed is correct, however when i test it in the smaller window, my climb speed is increased drastically and shoots me out the top of the ladder, this issue is fixed by not multiplying climbPpeed by time.deltatime, but then it wont be framerate independant
private void Climb()
{
if (!myCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))
{
//myAnimator.SetBool("Climbing", false);
myRigidBody.gravityScale = gravityScaleAtStart;
return;
}
float controlThrow = Input.GetAxisRaw("Vertical"); //value between -1 to 1
Vector2 climbVelocity = new Vector2(myRigidBody.velocity.x, (controlThrow * climbSpeed)* Time.deltaTime);
myRigidBody.velocity = climbVelocity;
myRigidBody.gravityScale = 0f;
}
Answer by leonelvg · Feb 06 at 10:34 PM
Rigidbody2D.velocity is already framerate independant (it produces a certain amount of movement on every FixedUpdate, which is framerate independant: you can change it on any method, including update, but it will not produce any effect on your character until the next fixed update (more precisely, until immediately after that next fixed update). By multiplying it by Time.deltaTime you are making its value depend on the framerate (as you noticed with the editor window size: games normally run faster on fullscreen, thus having smaller deltaTime and in your case making climbVelocity.y lower). For dynamic physics properties like velocity and forces, which only get applied on fixed update, you don't need Time.deltaTime. Only when changing kinematic properties like position, rotation or scale on update.