Collision Point

New releases and general discussions.

Post » Sun Nov 11, 2007 2:12 am

Is there a built-in way to retrieve the X and Y coordinate, of a collision between to sprites?
B
2
S
1
G
5
Posts: 31
Reputation: 1,462

Post » Sun Nov 11, 2007 2:48 am

No. When objects collide, there is usually a whole region of overlapping pixels, so you can't say a collision happened at only one pixel. Also, the collision algorithm is optimised and uses MMX to check 64 pixels at a time, so even if I tried to retrieve the first overlapping pixel, it would only be to within 64 pixels on the X axis - not particularly useful!

What are you trying to achieve? Usually there is a suitable workaround, such as using trigonometry, or finding the half-way point between the objects, as a good estimate.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sun Nov 11, 2007 3:11 am

I'm trying to create a custom physics engine, and understood that I need to know the point at which a collision happens. I am new to 2d physics, and only at a grade 9 math level, so maybe I haven't yet realized that there is a way to find these coordinates using trig (I'm relatively new to that as well :P ).

I just started understanding how programming works not to long ago, so sorry if that was a noobish question.
B
2
S
1
G
5
Posts: 31
Reputation: 1,462

Post » Sun Nov 11, 2007 3:16 am

It's not a noobish question, but why not use the built in physics engine? :) Add a Physics movement to your objects.

If you need the collision point to create an explosion or something, the halfway-point is a very rough approximation, ie. (Object1.X + Object2.X) / 2, (Object1.Y + Object2.Y) / 2. However this will not suffice for something as precise for your own physics engine - sorry, you're stuck there, that's what the Physics movement is for ;)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sun Nov 11, 2007 6:48 pm

I would suggest another thing :

Haveing the x and y of the "Only Point" collision mode customizable.
B
2
S
2
G
5
Posts: 512
Reputation: 2,674


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests