Lock player within a boundary?

Get help using Construct 2

Post » Mon Aug 26, 2013 8:30 am

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:

http://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 :(.
B
3
Posts: 3
Reputation: 181

Post » Mon Aug 26, 2013 8:55 am

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.
B
45
S
15
G
73
Posts: 2,002
Reputation: 43,386

Post » Mon Aug 26, 2013 9:04 am

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
B
20
S
8
G
2
Posts: 122
Reputation: 3,202

Post » Mon Aug 26, 2013 9:52 am

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Aug 26, 2013 6:13 pm

Wow, I'll try all of those and see what's best then. Thank you so much everyone :)
B
3
Posts: 3
Reputation: 181

Post » Mon Aug 26, 2013 9:59 pm

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.

http://imgur.com/v9A2yQYLuuthian2013-08-26 23:27:27
B
3
Posts: 3
Reputation: 181


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, MaxxMunnn and 4 guests