# Spawning 2 objects at same time problem

Just started using Construct 2? Post your questions here

### » Fri Aug 28, 2015 1:58 am

So I have a moving object, when that object is killed, it spawns 2 new smaller objects. Issue I am having is, they spawn on top of each other, collide, and one of them shoots off into a random direction, when I want them both moving in the same general direction.

Only way I found to avoid this was to use the move ahead action, but what I really want, is them to spawn side by side, relative to the angle they are moving at. Any help on how I might achieve this?
B
9
S
1
Posts: 49
Reputation: 551

### » Fri Aug 28, 2015 2:03 am

I am relatively new to Construct 2, but one thing I learned, is that one is shooting off because they can both collide with each other.
So to prevent that you would have to disable their ability to mutually collide.
Brick by brick, stone by stone.
B
57
S
25
G
18
Posts: 273
Reputation: 13,388

### » Fri Aug 28, 2015 2:14 am

Now if I do that, then the 2 just sit on top of each other with collision being disabled, plus, I really just don't want them to spawn on top of each other is it, there may be instances where they may collide, and I want that to happen.
B
9
S
1
Posts: 49
Reputation: 551

### » Fri Aug 28, 2015 1:14 pm

Here's an idea, I haven't tested it.

You should be able to use the "Move at angle" action on the new objects when they spawn to move them away from each other in the direction you want.

Description:
"Move the object a number of pixels at a given angle in degrees."

You'll want to get the angle that the original object is moving, then add 90 degrees. Spawn the first new object and "Move at angle" with that new angle by the new object's width for distance. (Or perhaps half-width if it spawns on its center)

Then take the original object's angle again, and subtract 90 degrees. Spawn the second new object and "Move at angle" with this new angle, again by the new object's width for distance.

If they still collide, add a bit to the width so that they don't collide.

Alternatively, if you don't need the spawn placement to be variable, you could specify two image points on either side of the original object, and spawn your two new objects at those image points.
B
12
S
4
Posts: 48
Reputation: 910

### » Sat Aug 29, 2015 2:42 am

Message: Prowl is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
I made a picture to better represent what I'm trying to do.Or even better, if I could say let the 1st one spawn in it's default position, and the 2nd one spawn anywhere within a certain radius of the 1st one at a random value, but far enough away so it doesn't collide with the 1st one upon spawn. But at the very least, I would like to have the 2nd object spawn either to the left, or right of the original object, based upon the direction of travel.
B
9
S
1
Posts: 49
Reputation: 551

### » Sat Aug 29, 2015 10:50 am

Valhallen's answer really is the best way I can think of to do what you're doing. If you want them to spawn very close to each other, though, with maybe momentary overlap, you could just wait a very short amount of time to enable collisions (have the objects start without it). The downside of this is that they won't collide with anything within that initial short range.
B
30
S
5
G
1
Posts: 63
Reputation: 2,454

### » Sat Aug 29, 2015 6:31 pm

Valhallen, that description sounds perfect. Now, the big question is, is there some way for the code to figure out the angle the original unit is moving at?

So my code will know the objects angle of movement, then one new spawning object adds 90 degrees, the other subtracts, and they each move 25 pixels in their correct directions. What would that code look like, and what action would I be entering it under?
B
9
S
1
Posts: 49
Reputation: 551