Jump to content

Stuck in the corners top-down game


MrJeanJean
 Share

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):
classic-behaviour.gif

What I'd love to have:
corner-to-corner-goal.gif

 

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.

Thanks for reading.

Link to comment
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.

Link to comment
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...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...