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

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

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

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

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

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

    distance(self.X,self.Y,asteroid.X,asteroid.Y)-asteroid.Width*0.3[/code:6koywpuv]
    
    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?
  • 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:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

  • You're welcome

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