Buggy Project Boot Results

Hi folks. In need of an assist.

Wrapping up project boost and discovered that my first build was completely buggy when applying and testing on my browser.

  • Collisions are disabled despite the build settings “Development Build” checkbox not checked

  • My Debug keys ‘C’ & ‘L’ however remain disabled.

  • My Rocket rotates on the y & x axis despite Freeze Rotation for both are enabled.

  • The framerate of gameplay is just plain awful. I expected a drop in framerate but from what I am witnessing is just abysmal.

  • My audio, rotate on Z axis, and thrust space key) remains intact!

I went as far as combing through my code countless times and clearing my browser’s history/cache just for giggles and laughs.

Any suggestions would be great. Thanks!

using UnityEngine;
using UnityEngine.SceneManagement;

public class Rocket : MonoBehaviour {

    [SerializeField] float rcsThrust = 100f;
    [SerializeField] float mainThrust = 100f;
    [SerializeField] float levelLoadDelay = 2f;

    [SerializeField] AudioClip mainEngine;
    [SerializeField] AudioClip rocketDeath;
    [SerializeField] AudioClip goalJingle;

    [SerializeField] ParticleSystem mainEngineParticles;
    [SerializeField] ParticleSystem rocketDeathParticles;
    [SerializeField] ParticleSystem goalJingleParticels;

    Rigidbody rigidBody;
    AudioSource audioSource;

    enum State { Alive, Dying, Transcending }
    State state = State.Alive;

    bool collisionsDisabled = false;
    
    // Use this for initialization
    void Start () {
        rigidBody = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>(); 
	}
	
	// Update is called once per frame
	void Update ()
    {

        if (state == State.Alive)
        {
            RespondToThrustInput();
            ResondToRotateInput();
        }
        if (Debug.isDebugBuild)
        {
            RespondToDebugKeys();
        }
    }

    private void RespondToDebugKeys()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            LoadNextLevel();
        }
        else if (Input.GetKeyDown(KeyCode.C))
        {
            collisionsDisabled = !collisionsDisabled;
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        if(state != State.Alive  || !collisionsDisabled) { return; }

        switch (collision.gameObject.tag) //ignore collisions when dead
        {
            case "Friendly":
                //do nothing
                break;
            case "Finish":
                StartSuccessSequence();
                break;
            default:
                StartDeathSequence();
                break;
        }
    }

    private void StartSuccessSequence()
    {
        state = State.Transcending;
        audioSource.Stop();
        audioSource.PlayOneShot(goalJingle);
        goalJingleParticels.Play();
        Invoke("LoadNextLevel", levelLoadDelay);
    }

    private void StartDeathSequence()
    {
        state = State.Dying;
        audioSource.Stop();
        audioSource.PlayOneShot(rocketDeath);
        rocketDeathParticles.Play();
        Invoke("LoadFirstLevel", levelLoadDelay);
    }

    private void LoadNextLevel()
    {
        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        int nextSceneIndex = currentSceneIndex + 1;
        if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
        {
            nextSceneIndex = 0; //loop back to start
        }
        SceneManager.LoadScene(nextSceneIndex);
    }
    private void LoadFirstLevel()
    {
        SceneManager.LoadScene(0);
    }

    private void RespondToThrustInput()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            ApplyThrust();
        }
        else
        {
            audioSource.Stop();
            mainEngineParticles.Stop();
        }
    }

    private void ApplyThrust()
    {
        rigidBody.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime); //odd behavior..
        if (!audioSource.isPlaying)  // so it doesnt layer
        {
            audioSource.PlayOneShot(mainEngine);
        }
        mainEngineParticles.Play();
    }

    private void ResondToRotateInput()
    {
        rigidBody.freezeRotation = true; // take manual control over rotation

        float rotationThisFrame = rcsThrust * Time.deltaTime;
        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(Vector3.forward * rotationThisFrame);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(-Vector3.forward * rotationThisFrame);
        }

        rigidBody.freezeRotation = false; // resume physics control of rotation
     } 
}

Hi Vinraal,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

That’s a known issue which gets fixed at the end of lecture “Spit & Polish” (currently #72).

Is the framerate very low or very high? If it is very low and if you use a laptop, plug the power cord in.

Collisions are disabled despite the build settings “Development Build” checkbox not checked

From the API: " In the editor isDebugBuild always returns true."


If you are experiencing issues with the movement, e.g. slow movement or laggy movement: There is a strange bug in Unity which prevents the rocket from flying properly 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?

If it does and if you are experiencing issues with the rotation, you could apply this concept to the rotation code.

Hi Nina! Thanks for assisting me again. :slight_smile:

Yes, I carefully reviewed a few chapters back as well and made sure changes were implemented. Took an evening and combed through it all and seems to be on virtually parallel to the course lecture changes.

yes I did go ahead and reviewed #72 and yes it helped me addressed the issue :slight_smile:

very low, choppier than a sous chef. This occurs in my wed browser build just to be clear. And to shed light on my situation and what may be the issue: I am using an Asus gaming laptop… from 2008… Sadly my battery has died years ago and the only way to power it on IS to plug it in. And no, ASUS does not replace or make my laptop’s batter any longer :grimacing:

I applied these changes multiple times with not so great results I am afraid. Rocket is stuck in place and will not thrust. Also regarding the Debug keys, I have it as:

``

    if (!isTransistioning)
    {
        RespondToThrustInput();
        ResondToRotateInput();
    }
    if (Debug.isDebugBuild)
    {
        RespondToDebugKeys();
    }
}

private void RespondToDebugKeys()
{
    if (Input.GetKeyDown(KeyCode.L))
    {
        LoadNextLevel();
    }
    else if (Input.GetKeyDown(KeyCode.C))
    {
        collisionsDisabled = !collisionsDisabled; //toggle
    }
}

I am pretty sure this is correct. From my understanding when creating a build without Development Build checkbox is unchecked that the debug keys are disabled. Do I have to remove the debug code to make this function properly?

Being the artist side on this particular platform’s spectrum, I seem to be struggling. However I confess I do enjoy the challenge of problem solving. I am also completely stubborn and will not stop until i figure this out lo.

I really do find these courses super insightful and I am starting to grasp it all but I need more practice. :sweat_smile:

I mentioned the power cord because many laptops have a battery saver mode. Maybe you could check the settings to make sure your laptop has got the maximum performance enabled.

When was the last time you uninstalled and reinstalled Windows? I’m still using a laptop from 2009 and have never reinstalled the system. It’s fairly slow now but I’m not using it for game development anymore, so I don’t care much.

Could you upload your game and share a link here? If the game is laggy for other people, too, there is a problem in your game. If it’s running smoothly, the issue is very likely your ancient hardware.

You don’t have to do that but you could to clean your code up. Since there are just two/three simple if-conditions, removing the code will not noticeably increase the performance of your game.

If the issue is your hardware, you could dive into performance optimisation by making all non-moving object static in their Inspector and by baking all lights that do not have to move and that are just decoration which do not have to affect the rocket. Also lower the graphics quality in the graphics settings. Add a Rigidbody component to all moving parent game objects that have a collider or whose children have a collider.

Currently using a Win 10 OS. A clean Install happened perhaps 3 years ago. And yes like you I dedicated this work station strictly for development.

Sure.

I will absolutely apply this after you and whoever else provides feedback to this. I am begining to think it may be my hardware but will exaught all possibilities before building a new PC :sweat_smile:

Thank you for the help and patience :slight_smile:

Game runs smoothly for me (except from colissions, as already mentioned).

1 Like

The game is running smoothly on my computer, too.

Nevertheless, please follow Rob’s instruction in this thread. Maybe there is a helpful error message in your browser console. If the collisions do not work even though you want them to work, add a few Debug.Logs to your development build to see what’s going on during runtime.

Well there is a relief. At least that narrows down one issue…

I did to the best of my ability as there seem to be nearly 100 options in the player settings inspector and had to hunt down an enable certain requirements as per instructions. I believe the unity version provided in the link was conducted on a previous version of Unity as I am running v5.6 on Windows.

I caught this if this is of any use:

After I applied the build using the steps provided by the link you sent, I was able to run the game, only this time my Debug keys were enabled on this build.

Nothing interesting in your console. At least nothing that helps me help you. :frowning:

To see if the issue is your game or just your hardware, you could play a couple of games made by other students. See here. If all Project Boost games are laggy on your device, it’s the hardware. Almost none of the games are optimised, so there is a chance that you can significantly improve the performance of your game.

If you cannot fix the issue, I’d suggest to remove the debug key code.

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

Privacy & Terms