How do I spawn explosion at point of impact

Get help using Construct 2

Post » Sat Aug 27, 2016 10:28 pm

In my game i have walls with different lengths, angles and elbows. I'd like to spawn a small explosion at the point of impact between the wall and ship.

I've tried a few things but it wants to spawn the explosions at the image point.

Any help with this would be greatly appreciated.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Aug 28, 2016 11:51 am

Are the ships always going to be facing the same way? You could create a new image point on the nose of the ship and spawn it there rather than the origin point.
B
47
S
17
G
82
Posts: 2,230
Reputation: 48,607

Post » Sun Aug 28, 2016 12:29 pm

When you have a collision you can get the xy's of the two objects, and compare their relative positions to each other.
For example if the wall was on the left side its x would be less than the ships x.
The problem is you can only estimate where the impact point is because C2 does not do per pixel collisions.
Instead you have a collision polygon, which tells you approximately how wide, and long your object is.
Usually the origin is in the center of the object, so a good estimate of where its side would be half the width, or half the height.
So with our example you could adjust the offset by saying self.x-(self.width/2).
wall x<self.x, self.x-(self.width/2)
wall x> self.x, self.x+(self.width/2)
wall y< self.y, self.y-(self.height/2)
wall y> self.y, self.y+(self.height/2)
Image ImageImage
B
171
S
50
G
180
Posts: 8,394
Reputation: 113,982

Post » Sun Aug 28, 2016 4:20 pm

Thanks for the replies.

Yes, the ship will move/rotate in 360 degrees. And the walls have different angles...

Image

I was trying to have a tiny explosion at point of impact but i may have to regulate that to the generic player flash, since there are too many walls to get a comparison.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Aug 28, 2016 7:17 pm

Invisible helper sprites should serve you well here. Surround your ship with permanent explosion sprites attached, default not animating and first frame blank/invisible. When that sprite collides with a wall, play the animation.

You may have to tweak the bounding box to fit the shape of your ship for best results. Small bounding box, as big an explosion as reasonable to fudge the actual impact location.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,699
Reputation: 64,446

Post » Sun Aug 28, 2016 8:00 pm

Ahh, never thought of that. Thank you. Although this may be quite a few added sprite animations. Possibly 36+.

I'll check it out.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112


Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 16 guests