Spawn particles on the point 2 object collide?

0 favourites
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Say, when a spaceship hits an asteroid and you want to draw sparks in the spot of the collision

    What I meant was it's something that would only be useful in some damn specific contexts. Depending on the size of the spaceship and the asteroid, it wouldn't even be necessary this kind of precision... Sounds overkill to me.

  • I used this solution for a laser beam: ... .capx?dl=0

    I'm guessing you can reuse this technique of stepping back in a loop for any object.

    This is probably the most efficient way of doing it, by the way. Way to go mekonbekon!

  • brunopalermo

    Cheers I'm not sure how well it would work for two complex shapes (say two stars) colliding, where the actual collision point could be a way off from the origin-to-origin intersection. Still, it's useful for simple scenarios.

  • Nice example!

    I didn't know you can change position/size of a sprite and then immediately test if it's overlapping another object in the same event. I thought you need to wait for the next tick.

    So using this technique I think you can find the point of collision with fairly complex shapes.

    Will need to define a few image points - one on each node of the collision polygon, where the red dots are.

    ("polygon" made with image points should be slightly larger/ slightly outside of the collision polygon)

    When collision with an asteroid is detected, take a small sprite, say 4x4 pixels, and move it from one image point to another (along the blue lines), constantly checking if it's overlapping the asteroid. Once it's overlapping, that would be your collision point!

  • Yoo-hoo!!! It works!

    Collision Point Detection Demo


  • Nice examples guys, I'm gonna try this when I get home! I thought it would be impossible. Basic things like this should be built in to the engine. ASHLEY. *cough*

  • Bravo nice one dop2000

    And mekonbekon

  • Nice stuff! Good to study further on.

  • dop2000 Very cool! I'll have a fiddle around with this and see if I can adapt it for continuous particles, so you can get some neat scraping effects when sprite slide across each other.

  • Cheers tarek2

  • how do i spell: "Ship.ImagePointY(loopindex=8 ? 1 : loopindex+1)"

    Also, why do i need only 8 imagepoints?

    the for and the while loop handles everything? Wow, please give out some comments on developing that.

    can we have a plugin or a behavior?

  • totoe

    (loopindex=8 ? 1 : loopindex+1) means "if loopindex=8 then 1, otherwise loopindex+1".

    It's a shorter version of "If then else" event.

    I'll explain again how I did this.

    You need to define an image points for every node (red dot) of your sprite's collision polygon.

    Image points should be located as close as possible to red dots, but a little bit outside of the collision polygon, just a couple of pixels.

    See this picture, green dots are my image points:

    Once a collision with the asteroid is detected, I take a small 4x4 pixels sprite called Detector©® and place it at image point 1.

    Then I move it from image point 1 to 2, then from 2 to 3, and so on, and finally from 8 to 1.

    While it's traveling, I constantly test if Detector it's overlapping the asteroid. If overlapping, I spawn particles at Detector location.

    I should add that my example is not optimized. Detector sprite travels long distances 1 pixel at a time, performing overlapping check every step. And at every pixel where it overlaps with the asteroid, it spawns particles. As a result, there could be 100-200 particle objects spawned! All this may cause huge lags on a slow computer or mobile.

    I don't think in a real game you need such precision, so you can move the Detector sprite 2, 4 or maybe even 10 pixels at once. This will significantly reduce the CPU load.

  • thanks for sharing!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay, managed to get continuous particles working: ... .capx?dl=0

    You can drag the asteroid around the ship and the particles will follow the collision point.

  • mekonbekon

    Pretty cool, I see you only using one particle instance, this should definitely decrease the CPU utilization. However there are a couple of small issues - if you leave the asteroid in the middle of the ship, particles are spraying from image point 1.

    Also, if asteroid is half-overlapping the ship, particles are spraying only from one side of it.

    Here is my version of continuous particles:



    I added some tweaks to decrease the number of particles instances.

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