- Home /
Game not running properly on slow machines (low fps)
Hello so i just finished making the player movement for my game and thought i would test it. I built the game and and ran it on my pc and everything worked fine, i gave it to a friend who has a worst pc than me and there was an issue where the wallrun wasnt working for him. I hoped on unity and capped my fps to something like 120 and as i thought that was the problem. The only difference between my movement and my wallrun is that the wallrun is called in update rather than fixed, i tried changing everything in the wallrun to fixed but it didnt help at all (it feels like the more fps i have, the greater the force when i jump off a wall) here are some examples:
Here is how it should work
Here is what its doing on "low" end machines
TLDR: Wallrun is not working properly on low fps probably because i am using update
Forgot to mention that any scripts that have to be sent will be sent
It would help if you sent the wall run script. Are you adjusting the force added to the player by Time.deltaTime
. This would make the force vary on different machines which may cause the effect described above, on PCs with lower frame rates.
Hey my post is under moderation so idk if you will see this but here is my code|
private void Update() { playerScript.collisionScript.CheckWall();
if (playerScript.collisionScript.CanWallRun())
{
if (playerScript.collisionScript.wallLeft || playerScript.collisionScript.wallRight)
{
StartWallRun();
}
else {
StopWallRun();
}
}
else {
StopWallRun();
}
}
public void StartWallRun() { playerScript.collisionScript.isWallRunning = true;
playerScript.rb.useGravity = false;
playerScript.rb.AddForce(Vector3.down * wallRunGravity, ForceMode.Force);
playerScript.playerCam.fieldOfView = Mathf.Lerp(playerScript.playerCam.fieldOfView, wallRunFov, wallRunFovTime * Time.deltaTime);
if (playerScript.collisionScript.wallLeft) {
tilt = Mathf.Lerp(tilt, -camTilt, camTiltTime * Time.deltaTime);
//Makes player stick to the wall
playerScript.rb.AddForce(-playerScript.collisionScript.leftWallHit.normal * Time.deltaTime * playerScript.movementScript.moveSpeed);
playerScript.rb.AddForce(Vector3.up * Time.deltaTime * playerScript.rb.mass * 100f * wallRunGravity);
}
if (playerScript.collisionScript.wallRight) {
tilt = Mathf.Lerp(tilt, camTilt, camTiltTime * Time.deltaTime);
//Makes player stick to the wall
playerScript.rb.AddForce(-playerScript.collisionScript.rightWallHit.normal * Time.deltaTime * playerScript.movementScript.moveSpeed);
playerScript.rb.AddForce(Vector3.up * Time.deltaTime * playerScript.rb.mass * 100f * wallRunGravity);
}
if (playerScript.inputScript.jumping)
{
if (playerScript.collisionScript.wallLeft)
{
playerScript.rb.velocity = new Vector3(playerScript.rb.velocity.x, 6f, playerScript.rb.velocity.z);
playerScript.rb.AddForce(playerScript.collisionScript.leftWallHit.normal * wallRunJumpForce * 2);
playerScript.rb.AddForce(Vector3.up * 20f);
}
if (playerScript.collisionScript.wallRight)
{
playerScript.rb.velocity = new Vector3(playerScript.rb.velocity.x, 6f, playerScript.rb.velocity.z);
playerScript.rb.AddForce(playerScript.collisionScript.rightWallHit.normal * wallRunJumpForce * 2f);
playerScript.rb.AddForce(Vector3.up * 20f);
}
}
}
public void StopWallRun() { playerScript.collisionScript.isWallRunning = false; playerScript.rb.useGravity = true;
playerScript.playerCam.fieldOfView = Mathf.Lerp(playerScript.playerCam.fieldOfView, fov, wallRunFovTime * Time.deltaTime);
tilt = Mathf.Lerp(tilt, 0, camTiltTime * Time.deltaTime);
}
Answer by BasomtiKombucha · Jun 11, 2021 at 08:51 PM
This is obviously hard to answer since we don't get much context to work with :) But a simple pointer I can give you is this: make sure that all manipulations you do with physics/rigidbodies are handled in FixedUpdate() methods, rather than Update() methods. You've mentioned that you tried to change everything in Wallrun to fixed. Are there any other forces at play, which are not done in FixedUpdate already?
Hello, no every force applied is called in update, the only thing that is not working is the wallrun
yeah you should really be doing all of your physics in FixedUpdate()
i tried that but, but there is either too much force applied or not enough
That doesn't really make sense, since FixedUpdate(), essentially, would enforce a regular application of force.
More to the point, you're double-dipping on Time.deltaTime multiplication by factoring it into Rigidbody.AddForce() yourself.
playerScript.rb.AddForce(Vector3.up * Time.deltaTime * playerScript.rb.mass * 100f * wallRunGravity);
That line, to give an example, doesn't need a Time.deltaTime multiplication, and should be in FixedUpdate().