# Full Collision Detection

This topic is 4127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my game I've been messing around with collision detection for some time, but now I am going to make a system that works! Ive decided that: I can group all my 3d entities into Players, NPCs, Terrain (Triangles), Objects(Still-life meshes), particles and projectiles (not sure if these should be one and the same) What I am working on at the moment is the Player/Npc against Terrain I wish to treat the character as the centre point of the ground he/she/it will occupy and the terrain is a list of triangles and squares. How can I find if the point is above, intercecting, bellow or on plan view outside the primitive?

##### Share on other sites
So you have a point and you wish to know if it is above, below, or on the same plane as a triangle, correct?

I'm assuming you know the normal vector of the triangle and a point on the triangle. First, find the dot product between the normal vector and the vector v = player - point, where 'player' is the point position of the player, and 'point' is the point you know to be on the triangle. If the dot product is above zero, then the player is above the triangle, if the dot product is below zero, then the player is beneath the plane, and if the dot product is zero then the player lies on the same plane as the triangle.

##### Share on other sites
Player .x, .y, .z; // Position of player
Point .x, .y, .z; // Point on the triangle
Triangle .a, .b, .c; // The triangles normal

v = Player - Point
... then dot product ... not sure how to do that

I thought about it a bit and decided

A = normal.x;
B = normal.y;
C = normal.z;
D = 0 - A*Point.x - B*Point.y - C*Point.z;

// A B C D thus a plane equation

// The original players position compares...
// Then the wanted position
// Collision if they are !=
EDIT: Well if they are in different groups of positive, negative or zero

However

o
----=======-------
o

^^ This would be seen as a collision (=) is where the triangle is, (-) is other space the plane divides

I think that both our methods will treat the above as a collision, can you think of some way round this?

[Edited by - ganbree on June 9, 2007 4:04:43 AM]

##### Share on other sites
Once you've determined if the point is close enough to the plane to count it as being on the plane, you can simply do a point-in-triangle test in two dimensions. Maybe do it in X and Z (or whatever the horizontal axes are for you) unless the triangle is vertical, in which case do X and Y. Alternatively, you could find which triangle you're testing against based on the X and Z, and then just test against that triangle.

It's much easier if terrain is a regular grid of some sort, however, since it's quick to find out which quad the player should be standing on (based on their X and Z) and work out the needed height at that point.

My lecturer has some notes about collisions with regular and irregular terrain, which also mentions the point-in-triangle test.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 17
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632660
• Total Posts
3007694
• ### Who's Online (See full list)

There are no registered users currently online

×