MrJeanJean Posted January 13, 2017 Share Posted January 13, 2017 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: In update player method I detect if the player is onWall() I check which face is on collision with body.blocked.right I get the tile in collision according to the position of the player (using snapToFloor) I getTileAbove() of current collide tile I check if this tile canCollide() 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 More sharing options...
drhayes Posted January 13, 2017 Share Posted January 13, 2017 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 More sharing options...
MrJeanJean Posted January 13, 2017 Author Share Posted January 13, 2017 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 More sharing options...
Fatalist Posted January 13, 2017 Share Posted January 13, 2017 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. Link to comment Share on other sites More sharing options...
MrJeanJean Posted January 13, 2017 Author Share Posted January 13, 2017 Interesting, thanks. I tried with arcade physics before with circle body with no difference/success. I guess p2 physics engine works differently. Let's try this ;-) Link to comment Share on other sites More sharing options...
Recommended Posts