Jump to content

Restric sprite movements to a perimeter?


Jerorx
 Share

Recommended Posts

Hi,

So I want a sprite that is controlled by the player to only be able to move within a specific perimeter of the map. I'm looking for ideas about how to achieve this in the best way possible.
My first idea was to put sprites all around the perimeter to act as borders, and to use collisions to prevent the player from leaving that area. The problem is : the borders obviously have to be immovable, but for reasons specific to my game, the player sprite also has to be immovable (although it has to be movable by the player, I don't want it to be moved when some projectile hits it). And unfortunately, collisions don't work when both sprites are immovable ;  they are still detected, but the sprites are not acted upon since they are both supposed to be immovable. I'm able to fire a processCallback tough, and I can use it to change the x or y coordinates of my player character, but the results looks like an ugly bouncing, not near as elegant as the standard collision handling.

Any ideas?

Edit : equally helpful would be a way to prevent my player character to move when hit by a projectile, without using the body.immovable property.

 

Second edit : Nevermind, I found the solution : I use overlap instead of collide to handle collisions between projectiles and the player's character. That way, they are not separated,hence the character doesn't move ; therefore, no need for it to have the immovable property, so problem solved. I leave the post in case someone has the same issue ...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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