I am moving a tilemap with SetViewOffset(), and trying to keep the player sprite in the middle with SetSpritePositionByOffset(). I set physics on for the player and for the sprites that he should not pass through.
When the player hits an obstacle, the physics correctly stops the movement even if I do SetSpritePositionByOffset(). The problem is, I then move the screen by the same amount with SetViewOffset(). This causes the player to drop off the center and the screen keeps scrolling while the player is staying put. I need to prevent the screen from moving while player stays put.
I tried to set the obstacles to specific category and use PhysicsRayCastCategory() to get hits on the left, right, top and bottom of the player on those obstacles. This works OK if the player moves directly left, right, up or down. But when they move diagonally, somehow it does not catch the hits with the ray casts. Is there some change in direction of the raycast if you set the sprite angle? Or should I play tricks with the player size? I try to raycase the top line and bottom line of left and right lines of the player depending on left/right or top/down dirs. As I said, works on straight angles but not diagonally.
Any examples on how to do this so it works, or some ideas on how to do this better otherwise?