Respawn issue in training section #3 unit 44

Rocket will not leave launch pad, vibrates only, will not move left or right

using UnityEngine;

using UnityEngine.SceneManager;

public class CollisionHandler: MonoBehaviour

{

void OnCollisionEnter(Collision other)

{

    switch(other.gameObject.tag)

    {

        case "Friendly":

            Debug.Log("This object will not hurt you");

            break;

        case "Finish":

            Debug.Log("You did it!!");

            break;

        case "Fuel":

            Debug.Log("Time to refuel");

            break;

        default:

            ReloadLevel();

            break;

    }

}

void ReloadLevel()

{

    SceneManager.LoadScene(0);

}

}

The CollisionHandler script doesn’t deal with the rocket’s movement, however it’s very possible the ‘vibrating’ is because the scene is continuously reloading from OnCollisionEnter calling ReloadLevel()

I would guess you have an object in your scene which isn’t tagged Friendly, Finish or Fuel and which is either colliding with your rocket when the scene loads or immediately after any input from the player. An easy way to test this is to temporarily comment out ReloadLevel() from the default switch statement.

Check all the objects in your scene and make sure that they have the appropriate tags assigned to them. Remember that they’re case sensitive, using the tag “friendly” in Unity’s inspector isn’t the same as “Friendly” and so on.

1 Like

Thank you, that was it! My ground was not tagged, when I changed it to “Friendly” the rocket lifted off and moved left/right and Respawn works.
Really appreciate your help.

1 Like

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

Privacy & Terms