Create object at random position outside of frame

0 favourites
  • 4 posts
From the Asset Store
Selection Frame
$0.25 USD
95% off
Selection frame like in RTS games, works both on mobile and desktop devices.
  • Hello everyone!

    First time on the forum and I'm getting into Construct and making games for the first time. I've been through the tutorial and it seems pretty easy to do some very simple things.

    I have a target in the middle and I want an object to be created at a random position outside of the game frame and directly go towards the middle (Craft.X and Craft.Y in my case).

    I just can't get the "Create at random position outside of frame and angle to" part.

    My game is 1080x1920 for my tests. My idea was to do a Random -300 to 0 and 1080 to 1380 for X and Random -300 to 0 and 1920 to 2220 for Y.... but I just can't get it done.

    Thanks everyone and have a great day!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 3 ways I can think of

    1/

    have 4 areas that you can create in and choose one at random, these four areas will be something like (-300,-300 to 1380,0) (top area), (-300,0 to 0, 2220) (left area), etc

    2/ create at (random( -300,1380),random(-300,2220))

    check if the sprite is on screen

    --if the sprite is on screen then destroy it and recreate it again at another random position

    loop this until it isn't on screen.

    3/ create at centre of screen

    pick a random direction and face that direction

    move forwards 1500 pixels

    (I would probably go with 3)

  • Wow! Thank you so much! I'm used to Javascript, but this visual approach is still new to me.

    You should have a Donate button as a respect for your help.

    Thank you so much for your time!

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