# Thread: Point of contact between two objects?

1. ## Point of contact between two objects?

I'm building a dumb physics engine (who isn't?) and it would be really handy to know the point of contact between two objects when they collide. Objects of varying sizes and shapes hitting at various angles and offsets.

2. It depends on whether Fine Collision is checked or not in the object properties. Available for active objects only. If checked, the collisions with this object and the others will be pixel precise (transparent areas do not trigger a collision). If unchecked, the collision will be done in box mode, with the rectangular box that surrounds the object.

Marv

3. What I'm after is the X and Y location of the point of contact. Is there a way to retrieve or calculate this information?

4. isn't where you've set the action and hot spot of your active objects?

5. Yes it exists a way, a proof-of-concept (at least).

Preparation: create an object (Active per example) with 2 variables (value type) named: "posXIs" and "posYIs" and one string variable named "checkState", put default to "WaitForOrder"

First: Give to your object a Qualifier (eg: Collectables)

Second: Create all Collectables objects by the method: Create Object!

In an event group named "_CheckPosition_":
Third:
If checkState is equal to "WaitForOrder"
Check Position condition for evaluating DISTANCE of the object which have "Collectables" Qualifier.
Stock X,Y position in Local Object variables (value type) : eg: "posXIs=%X_POS%", "posYIs=%Y_POS%"
Set checkState to the value "NowCheck" when checked for the checked object (DO NOT USE Qualifier here, or all objects will have value "NowCheck" if Qualifier is same, like "Collectables"!).
Repeat unless ALL Collectables are checked.

Four:
If checkState is equal to "NowCheck"
Check position of the object related to the PLAYER coordonates (X, Y)
When done, set checkState to the value "NearFrom"

Five:
If checkState is equal to "NearFrom"
After all actions are finished, set the checkState to the value "WaitForOrder" -so as it the check will be restarted!

if for any reason you must disable the check (eg: powerup which make the player unreachable), you would like then disable simply the event group named: "_CheckPosition_"

6. Tauman I understand what it is you're asking. The short answer is: No.

The long answer is: Really anything is possible... It depends on the size of your objects and shape and whatnot... If the objects are literally all circular, you could in fact use distance from the two object's centers in order to figure out the point between the two. But this is unlikely your situation... If you have odd shaped objects then you'd need to do something intensive like running a 1 pixel active in a big fastloop that places the 1 pixel active in a grid pattern near the central point of the two objects (figured by the distance between the two object's centers)

Then you'd have a condition in the fastloop to check if that 1 pixel active is overlapping both of your colliding objects at the same time... This means that 1 pixel active is directly at a point of overlap between the two objects. Then you'd stop the fastloop and use the x,y of that 1 pixel active as your contact position.

However I can't see this being very efficient...

7. Konidias I though about same idea, and it could be efficient only IF the loop will be started during collision. In manner On collision run the loop to verify distance between 2 objects and move it from there to find a place where it overlaps both objects.

8. Could you go about it with a kind of X Y targeting scope? What I mean is:
on collision with object- create an invisible line the width of the object at the base and create a line the height of the object at the side- these lines zip upwards and to the right,
where the two lines and the colliding object all overlap you have a coordinate.
this may be a little slow but it might be doable with fastloops...

9. Somehow, I have the feeling that this could be accomplished by comparing the angle and distance between object 1 to object 2... but I haven't tried this, so I could be wrong.

10. Originally Posted by Pineapple
Somehow, I have the feeling that this could be accomplished by comparing the angle and distance between object 1 to object 2... but I haven't tried this, so I could be wrong.
But this would only work with two round objects... If you need pixel perfect detection you'd have to use another solution.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•