How do I spawn object at collision point (Asteroids - Laser)

Get help using Construct 2

Post » Tue Aug 29, 2017 2:07 am

Hi forums,

I'd like to make an asteroids clone where the ship has a laser instead of firing projectiles. By laser, I mean when the mouse button is down, a ray is spawned and the nearest asteroid that the laser intersects with begins taking damage. I've got the above part down with a combination of "Is Overlapping" and "Pick Nearest". Now I was wondering if it was possible for me to grab the intersection point between the laser and the asteroid somehow so I can spawn some particle effects at that locations. The asteroid has a polygon bounding box and the laser is simply a long narrow rectangle sprite with its width set so that it extends from the ship to the asteroid.

I've hacked together something that's kind of crazy, but would like to know if there's a better solution. Currently I'm sending a stream of invisible bullets out of the ship and when there is a collision with an asteroid and a bullet I move the position of the particles to that collision point. BUT I'd rather not have to send out a steady steam of bullets to get this done.
B
6
S
2
Posts: 4
Reputation: 458

Post » Tue Aug 29, 2017 11:29 am

Hi @galtay, do you mean something like this?:

https://www.dropbox.com/s/gabg6r1yp5jgw ... .capx?dl=0
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Wed Aug 30, 2017 12:33 am

Yes! I've downloaded and run the file. Exactly what I wanted. I'll study the event sheet and see if I can understand what its doing. Thank you!
B
6
S
2
Posts: 4
Reputation: 458

Post » Wed Aug 30, 2017 1:04 am

I think I understand what's going on now. Its a very nice effect. If I'm understanding correctly it will only work for roughly spherical objects?

Code: Select all
distance(self.X,self.Y,asteroid.X,asteroid.Y)-asteroid.Width*0.3


If I had a big elongated rotating cylinder as opposed to the spherical asteroid we'd be in trouble in terms of the placement of the flare and particles. This will definitely make the asteroids game work but I guess that we don't have direct access to the collision systems coordinates in Construct 2. Is that right?
B
6
S
2
Posts: 4
Reputation: 458

Post » Wed Aug 30, 2017 8:47 am

@galtay

Yeah it's a bit of a fudge, which as you point out will only work with roundish objects. If you need a solution that works with irregular shaped objects you may have better luck using @Johncw87 's jcw_trace raycast plugin - it should give you an exact position:

plugin-jcw-trace-raycast_t172320
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Wed Aug 30, 2017 9:17 am

@galtay If you'd rather not use the plugin, I found a way to trace to the collision point on an irregular shape using a while loop:

https://www.dropbox.com/s/gabg6r1yp5jgw ... .capx?dl=0

cursor keys to rotate and move, left mouse to fire.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Thu Aug 31, 2017 1:54 am

Ha! That's a great idea. Find the intersection and then back off until there is no longer an intersection. I like it. Thanks very much.
B
6
S
2
Posts: 4
Reputation: 458

Post » Thu Aug 31, 2017 8:51 am

You're welcome :)
B
20
S
8
G
3
Posts: 458
Reputation: 4,055


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests