How to create an a (rectangular) area impenetrable by a sprite, when moved by X and Y coordinate

0 favourites
  • 2 posts
From the Asset Store
Awardkit
$3.50 USD
30% off
Create custom awards and achievement or use the many templates and create your own.
  • Hello,

    I am using a controller to move a sprite (vehicle) around. I want to create in the middle of the screen a rectangle that the sprite can not penetrate when the rectangle is visible.

    Currently, i use tilebackground to create a rectangle, and a button on the control makes toggles it visibility.

    To move the sprite i use the joystick on the control -- e.g. if its pressed right i increase the sprites X location by 5, and similarly in the other directions( right decrease by 5, up -- decreate Y by 5, down increase y by 5).

    This works great to move the sprite around.

    To test whether whether i can move over the rectangle i test for overlap between the sprite the the tilebackground.

    However, here i run into a problem -- once the sprite overlaps with the rectangle its essentially jumped into it (due to the increase of 5) -- and then can not move out of it anymore.

    What i intended was that it can not get into there in the first place -- the incremenets (or decrements) are stopped.

    Is there a better way to move a sprite via a joystick or to test for overlap so that the overlap never happens.

    (I am now thinking that i need to test the X+/-5 Y+/- 5 coordinate before moving that many units -- and thereby ensure that an overlap never happens.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Looks like i figured it out ...

    the "look ahead" only didn't work, but a negated condition did work -- i.e. when it does overlap and the joystick is still right -- move 5 units to the left to get out of the overlap.

    this worked,

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)