When rocket crashes while boosting the particle effects are still playing

Same goes with when you hit the landing platform

Hi BenCour,

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

Yep I’ve gone over it a few times. Maybe he talks about it later in the course or he just missed it. When you crash it turns off the movement script but because the particle effects are in the collision handler they keep playing I guess.

I notice this bug in other games that people have done as well so I guess he never fixes it

Try to call StopApplyingThrust(); at the beginning of the two *Sequence() methods. That should theoretically stop the particle system. The problem is caused by the first if-condition in the Update method: if (!isTransitioning). We change the value of isTransitioning, hence the RespondToThrustInput() does not get called anymore and does not stop the particle system. We have to do that outselves.

Let me know if it worked. :slight_smile:


See also:

I don’t know how I would do that

Sorry, my bad. I thought everything was in one class.

Do the following in the Movement class:

void OnDisable()
{
    Debug.Log(this.name + " was disabled.");
    StopThrusting();
    StopRotating();
}

Then reference the Movement component in your CollisionHandler component. You know how to do that. If not: Do it the same way as you referenced the particle systems and the audio sources. Let’s say, the variable name is movement.

Then you could do this:

void OnCollisionEnter(Collision other) 
    {
        if (isTransitioning || collisionDisabled) { return; }
        
        switch (other.gameObject.tag)
        {
            case "Friendly":
                Debug.Log("This thing is friendly");
                break;
            case "Finish":
                movement.enabled = false;
                StartSuccessSequence();
                break;
            default:
                movement.enabled = false;
                StartCrashSequence();
                break;
        }
    }

Unless I made a mistake, the OnDisable method in your Movement component should get called after movement.enabled = false; was executed. Of course, you have to assign the correct object to movement.

When you say do the following in the movement class do you mean the movement script? Then you have stopthrusting and stoprotating but I already have that somewhere else in the script. Also, I’m not sure how to reference the movement script in the collision handler script. I don’t think I’ve learned that yet. Lastly, my movement scripts is already assigned to the rocket.

Yes, that’s what I meant. :slight_smile:

Maybe you are not aware of it but you know how to do that. :wink:

Add this to the class which is supposed to reference (“link”) the Movement object:

[SerializeField] Movement movement;

Then save your script and drag and drop the game object with the Movement component into the exposed field in the Inspector. Done.

1 Like

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

Privacy & Terms