How do you make if-then scenarios?

0 favourites
  • 7 posts
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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)

  • 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.

  • 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.

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

    +Keyboard: [b]Y[/b] is down
    +System: For each [b]Object[/b]
    +System: [i]distance(player.x, player.y, object.x, object.y)[/i] < [i]200[/i]
       -> [lift objects...]
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)