platform game: How to detect if I am in-the-air

Community Forums/General Help/platform game: How to detect if I am in-the-air

Vampire(Posted 2012) [#1]
Hi! I work on making a platform game but I don't know how I can detect if the player is in the air so that the "jump" key doesn't work there. Please help (Side Note: I am using Draw3D via Blitz3D).


RemiD(Posted 2012) [#2]
One way is to make the platforms where it is possible to land "pickable", and use linepick from the player feet (slightly above) to below.
If nothing is picked, it means player is in the air.
If something is picked and the distance from the player feet to the picked point is too far, it means player is in the air.
If something is picked and the distance from player to the picked point is near enough, it means player is near the ground (above or below) you can now position it on the ground (with the picked point coordinates)

To manage this, what i do is that i use a PositionState which can be either OnAir or OnGround. When the PositionState is OnAir, the player is not able to jump, and when the PositionState is OnGround, the player is able to jump.

Last edited 2012


*(Posted 2012) [#3]
One of the best ways is to check to see if the player has jumped if they have set a variable called 'Jumping' to true and only set it back to false when they land on something, then simply check if they press jump against 'jumping' and if its true ignore the keypress.


TaskMaster(Posted 2012) [#4]
Wouldn't you also need a "falling" if you did that?


Dabhand(Posted 2012) [#5]

Wouldn't you also need a "falling" if you did that?



Nope, generally, you'll just be decrementing then incrementing the posY value until you hit the deck again, basically, when you hit the jump button, you set the jumping flag to true, which will allow you to ignore any further key presses until the player is back on the floor.

You dont really actually need to know anything else about the "jump", other then, yeah, your in the air and obviously while in the air, you apply whatever forces are needed to produce whatever kind of jump your after (As well as handling animation), because you'll be doing stuff like collision detection around the player anyway.

This is 2D mind, but, I imagine its the same in 3D too, apart from the Y-Axis may be opposite to your standard 2D implementation!

I used to love making platform games! :)

Dabz

Last edited 2012


TaskMaster(Posted 2012) [#6]
No, what I mean is if I fall off of a platform while walking, you don't want me to be able to jump while I am falling.


RemiD(Posted 2012) [#7]
TaskMaster>>There are several ways to write the code in order to manage this but here is what i do :

As explained in my previous post, the first thing i do is check with linepick or collisions where is the position of the player, in one of my projects, i check not only if the position of player is near the ground, or in the air, but also if he is against a wall (so that another routine can check if the player is able to grab a flat ledge or not).
So the PositionState can be either OnGround or OnAir or OnWall.

From this, i decide what is the PlayerActionState which is associated with an animation.
The PlayerActionState can be IsWalkingForward, IsJumping, IsFalling, IsLanding etc...
If the PositionState is OnAir and the gravity pull is low, this means player is starting to fall so there is a specific animation, if the gravity pull is medium, this means player is already falling during some time so there is another animation, if the gravity is high this means player is already falling during a long time so there is another animation (in this case player will probably crashes if he does not have a parachute !)

Last edited 2012


indietom(Posted 2012) [#8]
If not collison with player and floor = in air = true


TaskMaster(Posted 2012) [#9]
I was just trying to give Dabz a hard time. Wanted to point out the flaw in his super simple solution, knowing full well that it wouldn't be difficult to account for falling.

Remi, I do agree with your solution, just check if they are on the ground when they press the jump button. Simple enough.


Dabhand(Posted 2012) [#10]

I was just trying to give Dabz a hard time.



Git!!! :)


Wanted to point out the flaw in his super simple solution



Well, my super simple solution worked wonders for me, seriously, I've had Sonic the Hedgehog running and jumping about in Mario Land using it, and not once did it fail (Ahhhh good old BlitzBasic days)! :D

I also did Dizzy with the exact same code... See, the simpler, the betterererererererererererererererererererer... er!!! ;)


knowing full well that it wouldn't be difficult to account for falling.



:P

Dabz


RemiD(Posted 2012) [#11]

I was just trying to give Dabz a hard time. Wanted to point out the flaw in his super simple solution, knowing full well that it wouldn't be difficult to account for falling.


Ok ! :)


Vampire(Posted 2012) [#12]
Thank you folks! I have experimented enough just to find out that Draw3D cannot do collision detection though.