Time.deltaTime problems

Hi, i just recently put Time.deltaTime in my code and the rocket stop moving.
private void ApplyThrust()
{
rigidBody.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);

    if (!audioSource.isPlaying)
    {
        audioSource.PlayOneShot(mainEngine);
    }

    mainEngineParticles.Play();

}
before puting that piece of *Time.deltaTime, everithing was ok. Some help pls. Thanks

Hi Eduardo,

There is a strange bug in Unity which prevents the rocket from flying when it is selected in the Hierarchy. Try to select something else and click into the game window once to set Unity’s focus on the game window again.

The problem continues, also when I build the game, the rocket doesn´t move. Only affects to the thrust.

Did you try to increase the mainThrust value in the Inspector of the Rocket (and the Rocket prefab)?

Yes, actually to very high values and doesn´t work. This problem the first time I find it was when I put that code and the ship stopped. If I take away the code everything goes well but when I build and run the game the rocket goes really slowly I belive because the FPS. Inside Unity I run the game up to a 300FPS and in the web 60 more or less. Thats why I decided to reincorporate the *Time.deltaTime to run the game correctly but when I include that piece of code the rocket doesn´t move.

Did you try what I suggested in my first post in this thread: not selecting the rocket while playing your game?

You could also try to change the mass of the rocket in its Rigidbody3D component.

Yes, I try to decrease the mass and also not click in the rocket wile playing. None of them are usefull, it is like the movement doesn´t apply once I put that line of code

Could you log the mainThrust value into your console? What’s its value during runtime?

And which version of Unity do you use? Have you already tried to update?

Yes, I recently update to the last version of unity and the problems continues.

About the mainthrust:
imagen
It says 20 the same value that the rocket has in the inspector.

Could you please upload your project folder to GitHub (without the Library and the Temp folder). I’d like to look into the problem after the weekend.

Here is a helpful tutorial by Brackeys:

If you are in a hurry, please feel free to ask our helpful community of students for advice in our official Discord chat. Maybe I/we missed something obvious.

Hi, here is the link to the repository: https://github.com/supremebubbah/Project-Boost

Page not found. :frowning:

Sorry I didn´t realize it was private. Now should be public and able to see. Thanks for you help

Which one of the many scenes is the one I’m supposed to open to be able to test your game?

I tested the luna scene in Unity 2019.3.6f1, and your rocket moves perfectly fine. Ilo doesn’t work, though.


Updated Sun May 31 2020 15:09

Interestingly, the luna scene suddenly stopped working even though I didn’t change anything. I’m wondering if it’s a bug in Unity.


Updated Sun May 31 2020 15:41

Since the method belongs to the Rigidbody, the physics simulation actually takes care of the unconstant framerate. Furthermore, the method should actually be called in FixedUpdate. Ben probably wanted to keep things simple. It might be that his code worked for him because of a high(?) framerate. As aforementioned, the luna scene had worked for me but didn’t anymore after I tested other scenes.

I sent you a pull request on GitHub with the fix.

1 Like

Thank you very much for your help, now works perfectly!

You’re welcome. :slight_smile:

Did the pull request work?

Yes, also when build and run everything works. Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms