Monsters, players and collision...:(

Started by
2 comments, last by gorgorath 21 years, 3 months ago
Hey All, a hopefully simple question... First let me explain how the engine works. Whenever a monster has the player in it''s FOV it walks in a straight line toward the player, if not it follows an a* algorhitm to find the player. Do I have to perform collision detection(CD) on monsters that aren''t in the current visible "BSP leaves"? Or should I only perform CD when I need to render those entities? And another question about CD is how can I perform "sliding" across walls and steep surfaces? Cause right now there is some ''basic'' CD implemented but all it does is telling the player not to move whenever he ''hits'' a wall( just travelling the BSP nodes until you find the right one where the camera is in ).. cheers, Paul
Cosmic Keys to my Creations & Times
Advertisement
If you maybe used the bounding sphere collision detection method, with the radius of the sphere being equal to the farthest point from the center of your object, then that should resolve alotof your problems.

This sphere, of course, will surround your monster and will provide a nice approximation of when a collision has occurred. Nice and simple.

Having collision detection on all models in the game is beneficial in that with the extra data, the AI sould be more accurate and realistic.

[edited by - mathematix on January 20, 2003 1:44:26 PM]
Hmm, I already know how to do the CD by using bounding spheres,
but what I really mean is should I perform collision detection on entities( monsters, ammo etc. ) that is not really visible e.g. in a totally different room. But than again how do I let the monster wander the rooms to find the player? because when let''s say 5 or 6 monsters have spotted the player, i suspect that the FPS is dropping really fast.

BTW here is the collision detection method( JAVA ) that will return true if there has a coliision occured...

  /** * Passes sphere through the tree and checks for any parts in solid spc. * * @return  true  - sphere collides with solid space *          false - sphere in empty space */public boolean collideSphere(JDVertex3D sphereCenter, float sphereRadius, int node) {    int pointA, pointB;    BSPPercentage temp = new BSPPercentage();    JDVertex3D intersection = new JDVertex3D();    JDVertex3D sphereRadiusEnd = new JDVertex3D();    BSPPlane plane	= dungeon.planeArray[dungeon.nodeArray[node].plane];    BSPNode currNode = dungeon.nodeArray[node];	intersectingPlane = plane;	pointA = classifyPoint(sphereCenter, plane);    if (pointA == CP_BACK) {        sphereRadiusEnd.x = sphereCenter.x + (plane.normal.x * sphereRadius);        sphereRadiusEnd.y = sphereCenter.y + (plane.normal.y * sphereRadius);        sphereRadiusEnd.z = sphereCenter.z + (plane.normal.z * sphereRadius);    }    else {        sphereRadiusEnd.x = sphereCenter.x + (-plane.normal.x * sphereRadius);        sphereRadiusEnd.y = sphereCenter.y + (-plane.normal.y * sphereRadius);        sphereRadiusEnd.z = sphereCenter.z + (-plane.normal.z * sphereRadius);    }    pointB = classifyPoint(sphereRadiusEnd, plane);    //***************** IF BOTH POINTS ARE ON_PLANE    if (pointA == CP_ONPLANE && pointB == CP_ONPLANE) {        if (currNode.isLeaf == 0) {            // this is not a leaf so recurse            return collideSphere(sphereCenter, sphereRadius, currNode.front) ;        } else {            // This is a front leaf.Front Leafs are always empty so this is empty space            return false;        } // End If    } // End If    // Spanning front to back    if (pointA == CP_FRONT && pointB == CP_BACK) {        if (currNode.back == -1) return true;        getIntersection(sphereCenter, sphereRadiusEnd, plane.pointOnPlane, plane.normal, intersection, temp);        if (currNode.isLeaf == 0) 		{            JDVertex3D tempVertex1 = new JDVertex3D(intersection.x - sphereCenter.x, intersection.y - sphereCenter.y, intersection.z - sphereCenter.z);            JDVertex3D tempVertex2 = new JDVertex3D(intersection.x - sphereRadiusEnd.x, intersection.y - sphereRadiusEnd.y, intersection.z - sphereRadiusEnd.z);            return (collideSphere(sphereCenter, tempVertex1.getLength(), currNode.front) || collideSphere(sphereRadiusEnd, tempVertex2.getLength(), currNode.back));        }        else {            JDVertex3D tempVertex3 = new JDVertex3D(intersection.x - sphereRadiusEnd.x, intersection.y - sphereRadiusEnd.y, intersection.z - sphereRadiusEnd.z);            return collideSphere(sphereRadiusEnd, tempVertex3.getLength(), currNode.back);        } // End If    } // End If    // spanning back to front    if (pointA == CP_BACK && pointB == CP_FRONT ) {        if (currNode.back == -1) 		{			return true;		} 		getIntersection(sphereRadiusEnd, sphereCenter, plane.pointOnPlane, plane.normal, intersection, temp);        if (currNode.isLeaf == 0) {            JDVertex3D tempVertex1 = new JDVertex3D(intersection.x - sphereCenter.x, intersection.y - sphereCenter.y, intersection.z - sphereCenter.z);            JDVertex3D tempVertex2 = new JDVertex3D(intersection.x - sphereRadiusEnd.x, intersection.y - sphereRadiusEnd.y, intersection.z - sphereRadiusEnd.z);            return (collideSphere(sphereRadiusEnd, tempVertex2.getLength(), currNode.front) || collideSphere(sphereCenter, tempVertex1.getLength(), currNode.back));        }        else {            JDVertex3D tempVertex3 = new JDVertex3D(intersection.x - sphereCenter.x, intersection.y - sphereCenter.y, intersection.z - sphereCenter.z);            return collideSphere(sphereCenter, tempVertex3.getLength(), currNode.back);        } // End If    } // End If    // if we get here one of the points is on the plane    if (pointA == CP_FRONT || pointB == CP_FRONT ) {        if (currNode.isLeaf == 0) {            return collideSphere(sphereCenter, sphereRadius, currNode.front);        } else {            return false;        } // End If    }    else {        if (currNode.back == -1) {            return true;        } else {            return collideSphere(sphereCenter, sphereRadius, currNode.back);        } // End If    } // End If    // return false;} // END collideSphere  


Cheers

Paul
Cosmic Keys to my Creations & Times
You should definitely be doing collision detection and reaction for any moving entities, regardless of whether they are visible or not... have a think about it... if you look away from a monster, should it suddenly be able to walk through walls to get you?

I hope the answer is "no", otherwise that is likely to be one frustrating mother of a game

To cut down on the processing, maybe just have most of your enemies stand around "on guard" (only patrolling enemies need to be checked for collisions) until they spot the player, then they can give chase. If they lose sight of the player, they can fall back to a "hunting" heuristic, and if they can''t find the player for a certain amount of time, they resume their staionary "on guard" state.

This topic is closed to new replies.

Advertisement