Create object at random position outside of frame

Get help using Construct 2

Post » Mon Feb 24, 2014 5:02 am

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!
B
8
S
3
Posts: 24
Reputation: 725

Post » Mon Feb 24, 2014 8:34 am

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)
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Mon Feb 24, 2014 8:44 am

B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Mon Feb 24, 2014 7:44 pm

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!
B
8
S
3
Posts: 24
Reputation: 725


Return to How do I....?

Who is online

Users browsing this forum: Instrex and 20 guests