Hey all,
I’m creating a platformer, and so having precision with my movement is really important to me.
I thought all was perfect, until I used Application.targetFrameRate = 10
to simulate the game on a really low end PC, and I realized that my jump height is affected by frame rate, just a little bit, but enough to mess up the platforming. The coroutine is called when the jump button is pressed.
Does anyone know how to fix this to ensure that an exact jump height is achieved regardless of performance issues or poor frameRate?
Here’s my jump code:
public void SetVelocityY(float velocity)
{
if (!PlayerData.instance.isBeingKnockedBackVertically && !IsBeingKnockedBackFromDamage)
{
vel.Set(RB.velocity.x, velocity);
RB.velocity = vel;
CurrentVelocity = vel;
}
}
private IEnumerator Jump(float velocity, float jumpTime, float jumpPeakSlowDownTime, float jumpReleaseSpeed)
{
float elapsedTime = 0f;
//while within time threshold, and you are holding jump, and you are not dashing
while ((elapsedTime < jumpTime) && UserInput.instance.controls.Jump.Jump.IsPressed() && !IsDashing && !TouchState.instance.CheckIfHittingHead()
&& !PlayerData.instance.isBeingKnockedBackDown)
{
elapsedTime += Time.deltaTime;
SetVelocityY(velocity);
yield return null;
}
}