Collision position

Get help using Construct 2

Post » Tue May 08, 2012 3:50 pm

Is there a easy way to pinpoint exactly where the collision between two sprite take place?

Lerp would work really well but one of the sprite is growing in size from 20px to 200px and can collide with the other sprite anywhere there between.

I'm using lerp to calculate the distance between the middle points, so when the sprite is at 200px for example, the collision is a bit offset.

So lerp(ring.X,square.X,0.5) does work but not when the ring is at 200px size.

I'm creating a particle effect when they collide, so it has to be at the collision X,Y position.
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Tue May 08, 2012 6:19 pm

Your lerp system is probably about as accurate as it can be. You could try taking in to account the sizes of the objects to improve it slightly.

Collisions don't actually occur at specific points: collisions are always regions of the objects overlapping each other, which is going to be an unusually shaped polygon rather than a point. So since collisions have an area, there's no one point you can say the collision happened at. Estimating based on the object sizes, distance apart and relative angle is the best way to go.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue May 08, 2012 7:27 pm

Ah brilliant, found out by using the same lerp and adding one more action.

Moved particle at angle of the two sprites. Found out the distance by using the distance expression to calculate the length between the particle and the square. Works like a charm :)
B
7
S
1
G
3
Posts: 66
Reputation: 1,651


Return to How do I....?

Who is online

Users browsing this forum: SpartCrafter, Yahoo [Bot] and 23 guests