I’ve been trying to challenge myself with extra features and I’ve can’t seem to figure out how to make this work. I’d like to make it so the goal is only triggered if the ship is upright/landed. My first thought was “Is there a way to check which face of a collision shape is touching another?” or “Can you just have multiple collision shapes on the ship and detect which one was hit? (like a separate collision box for “landing gear”)” or is the a whole different way I’m not thinking of. I’ve read through some documentation but can’t seem to find an answer. Can someone point me in the right direction?
Wouldn’t the easiest way be to check the rotation of the rocket?
It’s a neat idea though, I’ve just added the following code to my project. I’m using C#, as it’s the language I know best. So you may need to translate this into GDScript if that’s what you’re using.
public float MaxValidLandingAngle { get; set; } = 0.35f; //may need some finetuning once the rocket model is final.
/// <summary>
/// Called after touching the landing zone.
/// </summary>
private void HandleLanding()
{
if (this.GlobalRotation.Z <= MaxValidLandingAngle && this.GlobalRotation.Z >= -MaxValidLandingAngle)
{
Print("Good landing");
}
else
{
Print("Eh, any landing you can walk away from, right?");
}
//todo, add a max speed check.
}
Of course, this would still consider somehow smashing into the bottom of the landing pad to be a “good landing”. Or if you “land” into the side with some sort of side-swipe move.
But you could add some tests on the rocket’s position to verify your rocket is above the landing pad. You get the colliding Node
in the event handler, so you have access to its Position
, so that should be possible. (Or add some obstacles/boxes around the landing pad so it cannot physically be touched from a weird angle. That’s always a nice trick to avoid adding more calculations, and probably what I will do )
Back on the Unity version of project boost my rocket had three fins like a tripod, I put a hitbox on the tip of each fin and you’d get bonus points if all three hit the pad first. I found if you could only win with a correct landing it limited the kind of levels I could design, though.
AFAIK there’s no issue in adding multiple collision shapes to an object and in fact this would be essential for adding collision to a complex object like a character with distinct moving limbs.