How do you make if-then scenarios?

Get help using Construct 2

Post » Fri Sep 28, 2012 7:59 pm

I'm currently trying to make a action-platformer game with construct 2 and have been running into some difficulties finding the information i'm looking for.

I'm trying to make it so that at the press of a button, certain objects a distance from the player rise into the air. I've already figured out the rising into the air aspect and played with physics enough to know what to do to have things shift around in the air. However, I'm trying to find something akin to the if-then statement so that I can do the following:

1 - If they are X distance from player when Y button is pressed, then they rise into the air.

2 - If there are blocks rising into the air and a direction is pressed, the player does not move but the blocks do

3 - if the blocks are X distance from the ground they stop and start hovering.

If I can figure out how to make if-then/else statements in this program i believe that i can solve this and many other related problems in my game, but i'm having difficulty finding the info i need. Any help in this regard would be greatly appreciated.

Herald of Time2012-09-28 20:02:43
B
7
Posts: 36
Reputation: 949

Post » Fri Sep 28, 2012 8:30 pm

Every event is an if statement. If the condition is true then it runs the action. There's a 'System: Else' condition as well that is true when the previous condition is false.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Sep 28, 2012 11:48 pm

Ah, i see. So that's what the condition else thing was. Thanks for that. I'm still confused about finding the distance from object event, if i could get assistance in that regard at least.
B
7
Posts: 36
Reputation: 949

Post » Sat Sep 29, 2012 1:03 am

to check a distance to the floor, you can make an invisible sprite follow your character's feet. This sprite's height will be at the distance you want your character to be hovering and then you'd just have to check for overlapping between this new sprite and the floor.
(You can probably achieve the same result with an overlap at offset (0,distance) from your character sprite, so without the need of an extra sprite)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Sep 29, 2012 2:42 am

To follow up with Yann's distance check. You can also set the sprites "image points" "origin" to where the feet are as to where you want to check your characters feet collision. That way you don't need an extra sprite or require to do any offsetting.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Sat Sep 29, 2012 7:09 am

It seems that I havent been as clear in what effect im trying to create.

What i'm trying to do is to make, at the press of a button, select objects within a certain distance from the player to rise. The objects would hover after rising a certain distance. Thank you for answering the latter problem, but the former problem is what i'm having the greater issue with as I plan to have more than one element which will involve distance from the playable character.
B
7
Posts: 36
Reputation: 949

Post » Sat Sep 29, 2012 1:20 pm

You can use 'System:Compare two values' along with the distance expression - distance(x1, y1, x2, y2). So you'd have something like:

[code]
+Keyboard: Y is down
+System: For each Object
+System: distance(player.x, player.y, object.x, object.y) < 200
   -> [lift objects...]
[/code]
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests