Game having different properties while ran in maximized and minimized mode

Hi! I’m working on the Project Boost lesson and am having some difficulties getting the game to run properly in the editor. Currently, the mass of my rocket is 0.05, which seems to be a good, solid mass that makes the game run fine while I’m testing my game with the game screen not maximized, but when I test the game with the game screen maximized the rocket goes crazy fast. How can I fix this?

Hi Alexander,

Welcome to our community! :slight_smile:

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.

If that didn’t work, try to remove Time.deltaTime from the AddRelativeForce method. Alternatively, test this potential solution in the Rocket.cs:

bool isThrusting = false;

private void RespondToThrustInput()
{
    isThrusting = Input.GetKey(KeyCode.Space);

    if (isThrusting)
    {
        ApplyThrust();
    }
    else
    {
        audioSource.Stop();
        mainEngineParticles.Stop();
    }
}

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

    mainEngineParticles.Play();
}

private void FixedUpdate()
{
    if (isThrusting)
    {
        rigidBody.AddRelativeForce(Vector3.up * mainThrust, ForceMode.Acceleration);
    }
}

Did this fix the issue?

Hi! I tested the provided solution code and it just ended up with my rocket not being able to accelerate at all, so I reverted back to my own code, without the Time.DeltaTime on the relative force. Here’s my code:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rocket : MonoBehaviour
{
    Rigidbody rigidBody;
    AudioSource splashing;

    // Start is called before the first frame update
    void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
        splashing = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        Thrust();
        Rotate();
    }

    private void Thrust()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            rigidBody.AddRelativeForce(Vector3.up);
            if (!splashing.isPlaying) //prevents weird audio glitches
            {
                splashing.Play();
            }
        }
        else
        {
            splashing.Stop();
        }
    }

    private void Rotate()
    {
        rigidBody.freezeRotation = true;

        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(Vector3.left);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(Vector3.right);
        }

        rigidBody.freezeRotation = false;
    }
}

In addition, I took a video showing the inconsistency problem between testing in maximized vs minimized view, https://www.youtube.com/watch?v=8YuhQBrOerI&feature=youtu.be

Thank you so much for your help!

To update, I’ve changed my code around a bit but am still seeing the issue. Here’s what ive got now:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rocket : MonoBehaviour
{
    Rigidbody rigidBody;
    AudioSource splashing;
    [SerializeField] float rcsThrust = 100f;
    [SerializeField] float mainThrust = 100f;

    // Start is called before the first frame update
    void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
        splashing = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        Thrust();
        Rotate();
    }

    private void Thrust()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            rigidBody.AddRelativeForce(Vector3.up * mainThrust);
            if (!splashing.isPlaying) //prevents weird audio glitches
            {
                splashing.Play();
            }
        }
        else
        {
            splashing.Stop();
        }
    }

    private void Rotate()
    {
        rigidBody.freezeRotation = true;

        float rotationThisFrame = rcsThrust * Time.deltaTime;

        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(Vector3.left * rotationThisFrame);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(Vector3.right * rotationThisFrame);
        }

        rigidBody.freezeRotation = false;
    }
}

The game works perfectly fine when I’m testing it in the game view, except when the game view is maximized, my player shoots up WAY too fast

Which version of Unity do you use? If you already updated to the latest stable version and if the issue persists, could you please report a bug to Unity via Help > Report a bug?

I am having the same inconsistency in my game. I’m using unity 2020.1.3f1 Personal

Hi Douwe,

Have you already tested my solution which I posted in one of my previous answers?

Yes, I have got it working now. Thank you!

This topic was automatically closed after 4 days. New replies are no longer allowed.

Privacy & Terms