Stuck in the corners top-down game

Recommended Posts

Hi there,
I'm a new Phaser user and already enjoy it!

I'm currently developing a standard top-down game. Now I'd like to "smooth" my hero motion when it collides wall corners.

What it currently does when you hold down the right key (logical and normal behavior):

What I'd love to have:

I really want to embrace the Phaser logic so I decided to follow the plan below:

1. In update player method I detect if the player is onWall()
2. I check which face is on collision with body.blocked.right
3. I get the tile in collision according to the position of the player (using snapToFloor)
4. I getTileAbove() of current collide tile
5. I check if this tile canCollide()
6. If the above tile can't collide I apply -50 to velocity.y

That sounds not bad but it's very heavy and I need to check all collide layers.
I'd just like to know how would you proceed? Or if there is an another-more-phaser-friendly way to do.

Share on other sites

That doesn't sound that heavy to me..?

There are some standard approaches, like snapping to grid when the player moves, or snapping to a 1/2 or 1/4 grid. You'd still end up doing some math to figure out how to squeeze through doors. You could also write a custom collision handler that does this for you and "warps" people through the door, maybe? Just spitballing.

Share on other sites

Thanks! Maybe is not that heavy indeed. I was wondering about this because I have to check the nearest door/wall on each layer (to detect other collide tiles not only on walls layer) and that for the four directions... and maybe later for other in-motion stuff like ennemies...

Although I did not really understand the snapping grid approach. You mean is like moving player tile by tile, to avoid that the player overlaps two tiles in same a time? Sounds easier of course...

Share on other sites

Generally this is often solved by making the corners of the character hitbox a bit curved, so it can naturally slide through doorways and over small obstacles. You can try that if you switch to p2 physics.