Game Development Community

Determining where collision happened

by Jason McIntosh · in Torque Game Builder · 03/01/2005 (12:11 pm) · 13 replies

What is the best way to determine which side of a rectangle one object collides with another? Could I use the %normal parameter from onCollision() to determine this? Or would a simpler way be better?

Any takers? :)

#1
03/01/2005 (12:20 pm)
The "onCollision" returns you the exact collision point (or points). See "contact points" in the "onCollision" callback.

If you need to know about the objects then you've got the "%srcObj" and "%dstObj" and you can get their positions and details as well.

The normal parameter gives you the direction of the collision surfaces in question.

- Melv.
#2
03/01/2005 (12:45 pm)
Ok, so %contacts is world coordinates of where each object touched?

And %normal is the surface normals corresponding to each contact? (So a normal of -1.0 would point which direction? Is that in radians?)
#3
03/01/2005 (1:06 pm)
@Jason: Yes, the contacts are the points at which the contact occurred.

The normal is a direction vector, not an angle and so there's no concept of radians/degrees. :)

- Melv.
#4
03/01/2005 (1:18 pm)
Thanks for the clarifications, Melv.

One more, though: if a %normal is 0, what does that mean? :) I know 1 and -1 would be either side of the plane, but what is 0? (Sorry for my weak math skills.)
#5
03/01/2005 (1:35 pm)
@Jason

A normal of 0 is pretty meaningless really as you can't determine direction from it.
#6
03/01/2005 (1:44 pm)
The reason I ask is that I'm dumping collision normals to the console and I get one pretty often that is 0.0. Here's an example.
#7
03/01/2005 (2:38 pm)
@Jason: I had that issue before but I thought it was fixed. It was related to collision overlaps, not disjoint collisions.

I'll add it to the list. :)

- Melv.
#8
03/01/2005 (3:57 pm)
I also get fractional normals.. is that ok? :) I assume you just look at the sign, but things like 0.66530 or 0.96625 do occur.
#9
03/02/2005 (3:14 am)
@Jason: When you said fractional normals, are you talking about the unit-length?

The normals are normalised and the components don't equal one, the unit-length should equal approximately one though.

I'll be checking that code when I get to it on the list. :)

- Melv.
#10
03/02/2005 (5:06 am)
Here's a screenshot of the console. That's from onCollision():
echo( "Normals: " @ %normal );
..just so you know where that output comes from.
#11
03/02/2005 (5:20 am)
@Jason: Yes, those normals are fine. Ignoring float precision, a unit-normal is correct if (x*x)+(y*y) = 1 is true.

Are you expecting "0 1", "0 -1", "1 1" and "1 -1" as these are only 0, 90, 180 and 270-deg normals?

- Melv.
#12
03/02/2005 (6:17 am)
I suspected that the "fractional" normals were ok. I have a ball with 16 sides, so that would explain why it's not all "cardinal direction" normals.

Thank you for the confirmation and your patience, and I apologize if I'm leaving confusion in the wake of my own confusion. :)
#13
03/02/2005 (6:19 am)
Not a problem. :)

- Melv.