How do I Spawn Object At Angle From Another Object

Get help using Construct 2

Post » Sun Nov 23, 2014 3:27 am

I would like to have a collectible 'pop' out once a crate is broken. I've tried using the Crate--> Destroy-- Create Object & System Create Object --> but it only creates it at the Crates Origin.

I know how to create Object at specific X & Y points and at a random angle, but not from a specific object (the crate) or at a random angle.

I've tried System-->Create Object--> Apple--> crate.x crate.y but i'm missing something with the random angle expression.

If anyone could help i'd be most thankful
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Nov 23, 2014 4:27 am

Can't you just set the apple to have a random angle when it's created?
B
17
S
4
G
4
Posts: 59
Reputation: 3,121

Post » Sun Nov 23, 2014 6:02 am

When a crate is destroyed it creates the apple (and assorted fruit). I'd like the fruit to 'pop' out of the crate making the player go and pick it up.

So i have to create the fruit at the crate and set the angle from the crate as well. I'm not sure exactly how to do this.

So far I have
Image

On the create sprite 2 (crate.y, crate.x) action I'm missing something in the random(35, 40) expression.

I tried = crate.Y(random(35, 40))

I'm not exactly sure how to write the expression after crate.y, crate.x
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Nov 23, 2014 6:28 am

Erm so if your game is strictly 2D (like a platformer) and you want the apple to pop out at a random trajectory (I assume that's what you mean by angle) you can give the apple the platform behavior but set the default controls to NO in the behavior settings for the apple.

Code: Select all
Playerbox1 - On Collision with Crate | Crate - Spawn another object Sprite 2 on Layer 3 @ ImagePoint 0
PlayerBox1 - Y < Crate.Y             | Crate - Spawn BreakCrate on Layer 3 at ImagePoint 0
                                     | Crate Destroy


This is how you should structure the first part of your code. After this you should do this:

Code: Select all
Apple - On Created | Simulate platform pressing UP
                   | Simulate platform pressing RIGHT


This method doesn't give it a random trajectory but it should work. To make it random you might want to use the bullet behavior on your apple and give it a random angle of motion when it is spawned.

I hope I understood what you were asking for.
B
17
S
4
G
4
Posts: 59
Reputation: 3,121

Post » Sun Nov 23, 2014 6:51 am

Hey thanks Aleyba.

I think you do. Basically, imagine if someone were inside a box and they tossed out an apple.

I'm not too worried about the random angle as much as i am about it popping out away from the crate. Right now when the player breaks the crate an exploding animation plays as the apple is created in the spot of the crate.

Two problems with this: 1) there is too much going on in that 48px area and 2) as soon as the player breaks the crate and the apple is created it disappears. You really don't even see it. I've tried 'pausing' the Apple Destroy but it looks/ plays weird.

I'll give your method a try.

Thanks again for the help.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Nov 23, 2014 7:08 am

No problem. If anything just use the bullet instead of the platform behavior. Give the bullet some gravity in the behavior settings. When the apple is spawned set the angle (probably to 90) so that it will shoot upwards and come back down.

You can tweak it to give you a random angle each time. Just make sure to make the random number between 180 and 0 degrees each time. ( Or whatever you want.)
B
17
S
4
G
4
Posts: 59
Reputation: 3,121


Return to How do I....?

Who is online

Users browsing this forum: Ryan Kocourek and 21 guests