Lock player within a boundary?

0 favourites
  • 6 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hello,

    I'm trying to make a game similar to a vertical shooter, but I need to constrain the player sprite within a certain boundary. I also need to make the player move based on the placement of the mouse or a finger.

    The best example I can think of is iOS shooters like the Cave series of games or Space Invaders Infinity Gene.

    Here's a shot of what I have so far:

    imgur.com/rFO9hrE

    I need to make the mouse work within the red bar only and I need the player sprite to move only left and right and not move past the green area.

    What would be the most effective way to accomplish this? I've tried the space shooter tutorial and the top down shooter tutorial but neither of them cover this :(.

  • For the player, just use collision (the sides are solid). For the red section I would create a sprite that covers the entire section and then have events for OnTouched(Red Sprite), where touching/clicking outside of the red sprite will do nothing.

  • another way to do this is manually do set player.x (or y) to touch.y or mouse.y.

    this way, it will only set the Y coorinates and not the X

  • You could use the expression clamp:

    clamp(x, lower, upper)

    Return lower if x is less than lower, upper if x is greater than upper, else return x.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wow, I'll try all of those and see what's best then. Thank you so much everyone :)

  • Hmm, one more question...

    I made a red sprite and have it so that when I touch an area within the red sprite the player will accelerate on the X plane towards the position of the touch input. My problem is I cannot make the sprite stop movement as soon as it is parallel to my touch input.

    I've tried making a "When sprite is at 0 angle to touch.y input stop moving" command but no luck :(. Any suggestions?

    And I'm sorry for asking noob questions. So new to programming...

    PS: I'm trying to make my character move like a platform would in a brick breaker game. Only the character cannot magically appear at an X coordinate. He must move to X and then stop.

    Here's what I'm using from a tutorial but I need him to move ONLY on an X plane, left to right from his starting position.

    imgur.com/v9A2yQY

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