- Home /
Why does my player accelerate and not stay constant
I have some basic code as I am completely new to development but can't see why my ball object constantly gets faster and faster and doesn't just go a constant speed the whole time.
Here is the code
left_pos = new Vector3(-0.01f, 0.0f, 0.0f);
playerGameObject.transform.position += left_pos * Time.time * ballSpeed;
Shouldn't it just add the negative value to move it left at the same rate the entire time?
Thanks
Answer by MacDx · Apr 01, 2018 at 01:31 AM
The problem is this line:
playerGameObject.transform.position += left_pos * Time.time * ballSpeed;
Specifically , Time.time which will return the time since the level started and that gets bigger every frame, thus the acceleration. What you probably want is Time.deltaTime instead.
Hope this helps!
Your answer
Follow this Question
Related Questions
Help with using keys to activate scripts 2 Answers
Please help with a simple collision. 3 Answers
Random.Range not working, no errors given c# 1 Answer
Simple problem regarding script copying 2 Answers