In my platformer game i use (this.body.blocked.down || this.body.touching.down) to determine if the player is allowed to jump or not. [my code on line 69]
This works great if the player is on a platform sprite. Unfortunately it allows the player also to jump if he is collecting a coin from above or jumping on a enemy and is pressing the up key at the same time.
this.body.touching gives only information about the direction but no information about the body it is touching.
If it would give me some information like this, …
{
none: false,
down: true,
left: false
right: false,
up: false,
body:(the sprite it is touching)
}
… it would be easy to determine if the player is touching a platform or something else.
If you use static bodies for platforms then you can test for this with body.onFloor(). Or body.blocked.down (same). So that’s one way.
If you want to record which bodies are colliding you would probably do that in a collision callback. If you set a flag of some sort, you would reset it at the end of the scene’s update method.
I did not know that there where 2 type of bodies (Dynamic and Static).
Now I now only use this.body.bocked.down for the player.
For the tiles: Instead of switching to a StaticGroup, I have set the second parameter of physics.add.existing(this, true) to true, which will create a static body instead of a dynamic body.
Here the updated code for the Tiles and for the Player.
I just ran into this post, looks very similar to one I just added
However although my platforms are static bodies, my objects are also in a staticGroup…
Is there a way to have an overlap but not return true for onFloor?
I have an simple repro based on the First Game example on my post body.onFloor true when overlapping with staticGroup body