- Home /
Question by
Dracolyte · Jun 13, 2021 at 12:01 PM ·
fpstime.deltatime
Time.deltatime doesnt make the game run the same on different fps
I have a huge problem. I have a script that increases the speed of all objects over time. Unfortunately the fps affects it. if the fps is 30 (or even lower), then the speed of the objects is slow and if the fps is more then 30, the speed of the objects is higher. How do i fix this? I want that the game runs the same no matter how high or low the fps is. Btw "speed" is for increasing "AllSpeed" and "AllSpeed" moves the objects.
My script:
public class BranchesSpeed : MonoBehaviour
{
private float speed = 0.00035f;
public float AllSpeed = 0.006f;
private PlayerController playerController;
private StartToPlay startToPlay;
void Start()
{
playerController = FindObjectOfType<PlayerController>().GetComponent<PlayerController>();
startToPlay = FindObjectOfType<StartToPlay>().GetComponent<StartToPlay>();
}
void Update()
{
if (!startToPlay.HasStarted) return;
if (!playerController.playerIsDead)
{
if (AllSpeed < 0.04f)
{
AllSpeed += speed * Time.deltaTime;
}
if (AllSpeed >= 0.023f)
{
speed = 0.0001f;
}
}
if (playerController.playerIsDead)
{
AllSpeed = 0;
}
}
}
Comment
Answer by NYX128 · Jun 13, 2021 at 12:49 PM
@Dracolyte If I could see the movement part of the PlayerController script then I might be able to answer.