Sign in to follow this  
ganbree

Full Collision Detection

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this