How do I spawn explosion at point of impact

0 favourites
  • 6 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • 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.

  • 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.

  • 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)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the replies.

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

    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.

  • 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.

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

    I'll check it out.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)