Best way to get Collision points x/y?

0 favourites
  • 14 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • I know its been asked a few times on these forums. As you can see here, the first collision works fine, but as it clips the side of the "energy wave" sprite, the "impact effect" is in the wrong place - its floating in space not on the object it hit.

    I was wondering what the best, quick and dirty "it looks good enough" way would be. Just something a little better than this. I don't want a ton of overhead (but maybe that is what is required?). Looking for suggestions from people who've had this issue before and what their solution was/is.

    I only need it for a couple of weapon types and its not that big of a deal if they are off sometimes.

    thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • We can cast rays with the line of sight behavior now, so you can cast a cone of rays out from the origin point, and get a higher resolution of impact coordinates.

    Alternatively you can pin invisible helper sprites to image points on your projectile as sensors and use those for collisions (disable the rest when one of them hits).

  • oh wow, thanks calminthenight for the R0J0hound thread, that second option, looping through the IP's x/y and averaging them is GREAT! I'm not entirely sure WHY that works! I will have to test it more...

    also thanks oosyrag those options seem would also work!

  • So if I'm looking at that right looks like you have the origin of the wave at the front so you're doing something like this?:

    on wave collides with ship
    -- create explosion at (wave.x, wave.y)
    -- destroy wave

    The main idea i have is you can clamp the explosion position to the shape of the ship. This is simpler when the shape is simple.

    Since the ship isn't rotating is you can clamp the position that you create the wave to the bounding box of the ship. Anyways that works well for unrotated box shapes, so the ship from the right could still have floating hits.

    on wave collides with ship
    -- create explosion at (clamp(wave.x,ship.bboxleft,ship.bboxright), clamp(wave.y, ship.bboxtop, ship.bboxbottom))
    -- destroy wave

    If you want to clamp to a rotated box it would be this as long as the ship's origin is centered.

    on wave collides with ship
    -- create explosion at (wave.x-ship.x, wave.y-ship.y)
    -- set explosion position to (self.x*cos(ship.angle)+self.y*sin(ship.angle), self.x*cos(ship.angle+90)+self.y*sin(ship.angle+90)
    -- set explosion position to (clamp(self.x, -ship.width/2, ship.width/2), clamp(self.y, -ship.height/2, ship.height/2))
    -- set explosion position to (self.x*cos(ship.angle)+self.y*cos(ship.angle+90)+ship.x, self.x*sin(ship.angle)+self.y*sin(ship.angle+90)+ship.y)
    -- destroy wave

    Similarly you can clamp to a circle shape. Here a circle with radius 100.

    on wave collides with ship
    -- create explosion at (angle(ship.x,ship.y,wave.x,wave.y), min(100, distance(ship.x,ship.y,wave.x,wave.y)))
    -- set explosion position to ( ship.x+self.y*cos(self.x), ship.y+self.y*sin(self.x))
    -- destroy wave

    Or even any convex shape. Although that can take more thought. Here is a triangle.

    on wave collides with ship
    -- create explosion at (wave.x, wave.y)
    -- explosion: move -max(0, (self.x-ship.x)*cos(180)+(self.y-ship.y)*sin(180)-50) pixels at angle: 180
    -- explosion: move -max(0, (self.x-ship.x)*cos(-60)+(self.y-ship.y)*sin(-60)-50) pixels at angle: -60
    -- explosion: move -max(0, (self.x-ship.x)*cos(60)+(self.y-ship.y)*sin(60)-50) pixels at angle: 60
    -- destroy wave

    And here's another way to do the rotated rectangle:

    on wave collides with ship
    -- create explosion at (wave.x, wave.y)
    -- explosion: move -max(0, (self.x-ship.x)*cos(ship.angle)+(self.y-ship.y)*sin(ship.angle)-ship.width/2) pixels at angle: ship.angle
    -- explosion: move -max(0, (self.x-ship.x)*cos(ship.angle+90)+(self.y-ship.y)*sin(ship.angle+90)-ship.height/2) pixels at angle: ship.angle+90
    -- explosion: move -max(0, (self.x-ship.x)*cos(ship.angle+180)+(self.y-ship.y)*sin(ship.angle+180)-ship.width/2) pixels at angle: ship.angle+180
    -- explosion: move -max(0, (self.x-ship.x)*cos(ship.angle-90)+(self.y-ship.y)*sin(ship.angle-90)-ship.height/2) pixels at angle: ship.angle-90
    -- destroy wave

    Sometimes you can have complex shapes be made up of multiple simpler ones. It just depends on what you're after.

    Anyways, just an idea.

    Edit:

    here's an example:

    dropbox.com/s/xcg99crdntoa3lf/convex_clamping.capx

  • R0J0hound I was following your other thread suggestion, but I guess it doesn't work when I apply it. It just spawns it, in the same place as I was before and only when its a straight on collision (but not always). If it hits the side the code doesn't trigger. It must have something to do with the overlap during Bullet? also this code is triggered from OnCollision (opposed to isOverlapping)

    perhaps I should follow your other suggestions...

  • and to complicate things the "energy wave" has 4 hp, so it can hit and damage 4 things before it dissipates.

    AND there are multiple collision boxes since it is animated to "grow".

    looking at your clamp example now...

  • Cool. Glad it was useful.

  • R0J0hound oh it seems like when the ship getting "hit" is a thin rectangle and the wave is perpendicular it doesn't quite work.

    Was the dropbox example you gave a generic triangle/square/rect? or was it for a specific shape?

    My "Allcraft" family has all sorts of shaped ships, is there a good generic way to do it?

  • Made a quick experiment with line of sight, might be useful for reference.

    dropbox.com/s/9axc8tp0jkmyi8x/accuratecollisiondetectionexample.c3p

    Still some bugs to work out, such as when the bullet hits a second object while still overlapping one that was hit before. The add obstacle action doesn't seem to care about picked instances.

    Edit: I'm logically stumped for now on how to fix the issue with multiple overlapped objects on collision and 'hitting' the wrong/previous object. Might be a hard limitation if you can't pick instances to interact with for line of sight.

  • It was a specific shape. each action has an angle and distance to specify the lines that make up the shape. For example a triangle can be made up of three lines: red,blue and green.

    That said, it can be made generic but in c2 I can't access the collision polygon so I'd use imagepoints instead. As long as the points make up a convex shape and points are placed clockwise. Although the winding order can be worked around.

    edit:

    Here you go:

    dropbox.com/s/xp1tprnefmdwf0b/convex_clamping_generic_with_imagepoints.capx

    Just as long as it's a convex shape and the origin is within that shape. CW or CCW doesn't matter.

  • oosyrag honestly that was the direction I was sort of headed down and I couldn't figure it out.

    R0J0hound awesome! thanks. all my shapes are convex, I will try this out!

  • R0J0hound yes! (I changed them to polypoints) I think that will work! it doesn't work well on convex shapes that are narrow, but its never outside the convex shape, so that is fine enough for me! I don't really have any narrow shapes other than that test target thing.

    very much appreciate everyone's help! thanks so much!

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