I want to implement a part of my game where if the player stands on a hitbox area, he is able to use a special item. I have "this.physics.add.collider(); and the same with overlap, but I’m looking for something I can put in update, to check IF currently colliding or overlapping. Something like “isColliding” but how do I tell it what it is colliding WITH?
Physics bodies store their current collision state (in blocked
, touching
) but not which bodies they’re colliding with.
You would have to store that state yourself (in a variable, property, or player.data
) in the collider/overlap callback, read it in update(), then reset it at the end of update().
Could you show me an example of this please?
Thank you Samme for the help and quick response! One thing I noticed about overlap, is that my player seems to just fall right thru the floor tile when overlapping. I’m not sure why this is happening, or how I can fix it. I’m using arcade physics.
Is the floor your player is falling through a Sprite or a tile?
You can use:
scene.physics.overlap(GameObject1, GameObject2, callback, preProcessCallback, callbackContext)
This will return true if there is a collision, and false if there is not a collision.
https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.ArcadePhysics.html#collide