This problem only occurs if you actually move the player ship during take off, or rather, try to. What is happening is that you move up during take off (via the Timeline) and the moment you exit the BoxCollider on the LandingPad we are assuming take off is good, but if the player move the ship left, right or down fairly quickly, the player makes contact with the BoxCollider on the LandingPad again and, because we’ve assumed the next time they did it would be at the end of the game, the Game Over condition is met.
There are better ways to resolve this issue, but it’s getting increasingly difficult to write good solutions in the existing code, but the following will work for now;
Update LandingPad.cs
using UnityEngine;
public class LandingPad : MonoBehaviour
{
private void OnTriggerExit(Collider other)
{
PlayerController playerController = other.gameObject.GetComponent<PlayerController>();
if (playerController)
{
gameObject.GetComponent<BoxCollider>().enabled = false;
Invoke("ActivateLandingPad", 10f);
}
}
private void ActivateLandingPad()
{
gameObject.GetComponent<BoxCollider>().enabled = true;
}
}
What the above does is to catch the moment the player ship has left he BoxCollider and then it disabled the BoxCollider, as such, any player movement doesn’t trigger another collision.
The downside of this approach is that because you are relying on that BoxCollider for triggering the end of the game it needs to be turned back on again. That’s what the Invoke method is doing. it calls the ActivateLandingPad after a rather arbitrary period of time - 10 seconds - I set it to this because this should be enough time for the player ship to be moved away from the LandingPad by Timeline, but its less than the duration to get around the entire route of the rails, thus, it’s back on before you come back around to it.
This is fairly messy as solutions go - but it does work and will perhaps buy you some time until a better solution is in place.
Hi, Rob, I’m very excited about getting the new assets from Daz3D I think it will work out just fine. I hope if I get stuck I can reach out to you if you can spare the time. I plan to make the player get out of a new ship from Daz3D assets store I will buy. and I will create a new scene with at least 8 levels where the player is walking or running around as an fps game shooting aliens I will buy at the Daz3D asset store. in three weeks I will buy some of the assets and terrain scenes will show when I have it. Thank you for all you do.
Not wishing to kill any enthusiasm but I would really focus on tightening up/improving what you already have before trying to add any further complexity to it. The course content delivers a very specific outcome, not one that is particularly finished, as you’ve already discovered with regards to how to loop around or end the level. These are the kind of things that should be considered at the start before heading down a path of writing code.
One thing you could consider, which may make it easier, would be to consider creating these new features in a separate project, that way you can experiment with the new features, overcome whatever problems you encounter without the existing game’s code base. Then, when you’re ready you could look at bringing those features in to the main game. Just a thought.