Checking if player falls down hole?

so I’m trying to get my player to fall down a hole like in Sonic the Hedgehog. How would I do this? I have simple transparent-colored tiles to mark where the hole should be triggered, but I want it to stop the camera from following the player when the player has fallen below the trigger tiles. How to check if `both` above tile `as well as` below tile?

Thank you

hello?

Just add an invisible hitbox, or a zone. When collision or intersection is detected, stop the camera and animate your player downward.

Yea, that’s what I did but it didn’t work.

I have hitboxes, but can’t seem to detect both when my player is above them and below them.

anyone can help???

hello?

Is it just to stop following the player when he falls below the bottom of the map? Then just set the camera bounds (bottom) at the start of the scene. No need for triggers.

All physics collisions are overlap tests. But you can add as many physics-enabled Zones as you need, above, below, or wherever.

Yes, when the character falls down the hole, the camera stays in the hole the character fell in but detaches when below the set trigger zone ( or map ) either or.

i’ve already tried checking if velocity is going down but that didn’t work.

someone can help me??

Did you try these?

1. Set camera bounds (`bottom` not below hole); OR

2. overlap zone with callback

Hi, I think that all solutions in game development must be subconscious. So I’ll try to help you with my methods. Just think simply. How can you detect what you need yourself?

Of course in this post I’ll explain how to resolve your issue. But I think, that it will be better to explain how you can get solutions for you.

Always try to use simple logic in your solutions. In your case you have zone, where you need to detect that character had fallen down into hole. So you need to detect 2 intersections.

1. intersection with zone’s top line
2. intersection with zone’s bottom line
Which is very easy to detect. Most of game objects in Phaser 3 have function called `getBounds()`. This function returns `Phaser.Geom.Rectange` type object, which shows bounds of your game object in the world. So you have 2 objects: character and hole. You can get bounds of them. Then you can get interesting lines to check for intersection.
``````var characterBounds = character.getBounds()
var holeBounds = hole.getBounds()
``````

The line that must interest you in character is 2nd or 4th line (vertical). So you can get it by calling

``````var characterVerticalLine = characterBounds.getLineB()
``````

Lines that must interest you in hole are 1st and 3rd (horizontal lines). So you can get them by

``````var holeTopLine = holeBounds.getLineA()
var holeBottomLine = holeBounds.getLineC();
``````

Next step must be detection of their intersections.
So let’s define a function, that will do that for us and call it in our scene’s `update` function.

``````function checkForCharacterFallDown(){
if(Phaser.Geom.Line.Intersects(characterVerticalLine, holeTopLine) ){
scene.events.emit('characterHittedTopLine');
}
if(Phaser.Geom.Line.Intersects(characterVerticalLine, holeBottomLine) ){
scene.events.emit('characterHittedBottomLine');
}
}
``````

then call this in your update function

``````function update(){
checkForCharacterFallDown()
}
``````

in your `create` function set listeners for event `'characterHittedTopLine'`.

``````scene.events.on('characterHittedTopLine', onHittedTopLine)
``````

lets define function `onHittedTopLine`

``````function onHittedTopLine(){
scene.events.once('characterHittedBottomLine', onHittedBottomLine);
}
``````

lets define function `onHittedBottomLine`

``````function onHittedBottomLine{
scene.events.off('characterHittedTopLine'); // if you want stop listening this event
scene.cameras.main.stopFollow(character); // not sure that function calls that way, but you understood the idea
// and then other things that you planned to do when character falls down into hole.
}
``````

just optimize your code to do checks only for holes that are visible in your camera and everything will be okay.

so what would `hole` be? hole right now is actually just tiles i erased from the map.

how am i supposed to do `var holeBounds = hole.getBounds();` ?

Would `hole` be this? :

``this.holeLayer = map.createDynamicLayer ( "hole", tiles );``

I’ve no experience in working with tile maps, but I’m sure that you can get hole’s position. I’m sure that you can get position of every tile and you can make yourself hole’s bounds rectangle without getting bounds.

``````new Phaser.Geom.Rectangle(x, y ,width, height)
``````

maybe a silly answer but im not clear where your holes are located , if they’re always bottomside you could just check
if(playerobject.y < something)

probably not what you need but in case of holes at the bottom perhaps the simplest way