Spawn an object in the exact spot where 2 objects collide?

0 favourites
  • 6 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi All

    this is my first Post, also my first time working with Construct 2, I've came with this concern, maybe this problem is solved somewhere on these posts, and it's so easy to fix, anyway, I'm working on a project which is a game that involve a collision of two object and that action such causes a creation of other object.. But I don't know how to specify that object spawn in certain spot (the point that those two object touch themselves!)

    Putting this more easily to understand, imagine a Ball hitting a big wall, and when the ball hit, it bounce back

    Ball=object

    Big wall=object

    Ball bounce=the object that spawn

    any help?

    thanks in advance!

    sorry my bad english (not my mother language)

  • I'm not sure that construct gives you any way to work with collision data at all. As far as I've seen it only allows you to collect the fact that a collision has occurred. A less accurate method would be to collect the x, y position of the object you are colliding with and spawn the object here...

    A more accurate way would be to create your own buffers, or sensors. Little objects so far away from the object like, tiny clear squares, and then spawn the object at the location of the square the hits.. This would be tricky and require some overhead, because you're going to have to turn off the sensors as soon as there's a collision, and then turn them back on when they are overlapping nothing but the ball... or set them some pixels away from the ball..

    Honestly, neither seem really professional. I'd like to see the proper answer for this. I've yet to see anyone talk specifics on collecting collision data...

  • For purposes of speed, collision detection between two objects generally terminates once a single point of intersection has been found. Since you can't guarantee that the first detected point was the only point of collision -- or even representative of the average -- the locality of this point is of little use.

    Really, you'll have to handle this on a case by case basis. It's easier to approximate a reasonable point of collision between simple shapes than complex ones, and different mathematical models will be useful for different combinations of shapes.

    In the case of a ball hitting a wall, you can use the radius of the ball and its angle of motion to approximate the point of collision using some basic trigonometry.

  • The chipmunk physics behavior has a way to get the point of collision, but other than that you'll have to calculate it yourself for anything else.

    For one idea you could look here:

    That capx has a way to calculate a normal. If you create an object at the ball, and then move it by the radius in direction of the normal with the "move at angle" action, then you should get a point of collision.

    I'd make a capx but my pc seems to be dying bit by bit and C2 has been the latest victim. I'll see if a reboot helps.

    For the absolute most precise way you could use the SAT (separating axis theorem) on the ball and wall. That's usually used for resolving a collision, but it can also give you the point of collision. I've made some capx's of it elsewhere on the forum.

    Or you can do the math directly. Find the formula for the distance between a point and a line and use it to find the distances to the four lines of the box, only check that the point if projected on it land within the segment, then find the distances from the four corners. The closest of any of those will be the one you use to get the normal and collision point.

    I've done both before, and they work well although can be a bit complex to setup. An approximation is usually good enough as with the first idea.

  • thanks all for the replies, I had used the JeremyBenson advice, I used littles transparent squares all long the "wall" to set the hit spot, luckily all the hit spots of the wall are way long the X.. so, I forget the Y axis.. BUT... the thing is now the "BALL" hit sometimes two squares spawning the "Bounce object" duplicated..

    a little help please

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I thought he meant objects positioned around the ball, but I may be wrong.

    Anyway's here's an example of the first idea i had:

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

    It's good enough for the bullet behavior because the bullet behavior doesn't have perfect bounces either.

    More precise stuff here, if you're ambitious.

    viewtopic.php?f=148&t=91829&p=718888&hilit=SAT#p718888

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