ganbree 152 Report post Posted June 8, 2007 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? 0 Share this post Link to post Share on other sites
Samith 2460 Report post Posted June 8, 2007 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. 0 Share this post Link to post Share on other sites
ganbree 152 Report post Posted June 9, 2007 Player .x, .y, .z; // Position of playerPoint .x, .y, .z; // Point on the triangleTriangle .a, .b, .c; // The triangles normalv = Player - Point... then dot product ... not sure how to do thatI thought about it a bit and decidedA = 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 zeroHowever o----=======------- o^^ This would be seen as a collision (=) is where the triangle is, (-) is other space the plane dividesI 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] 0 Share this post Link to post Share on other sites
MrEvil 970 Report post Posted June 9, 2007 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. 0 Share this post Link to post Share on other sites