-
|
|
Collision Detection - How?n00b time
|
Hey all,
First off, I'm an artist, not a good programmer, but I'm learning. I'm trying to create a very very basic engine to test out stuff I create in XNA. Here's the basis for my engine: A guy walks around on terrain. Not too hard, right? I can get my models into XNA, I can animate them, normal map them, anything the samples show me how(copy-paste coding basically :\). All I need is to be able to do some collision detection with something other than collision spheres. something that will detect where my player collides with the terrain (terrain will be modeled, not height map, It's complex map geometry). Any suggestions?
*I've heard of some Dx stuff with triangle collision detection, but never found many articles on it, is this worth looking into? also newton physics?
thx ahead of time, -Chris
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
there are 2 classes in xna that help you in collision detection BoundngBox and BoundingSphere. in the bounding box class you define 2 vectors one is the minimum and one is the maximum then an invisible box is created between them you can use the .intersect method to determine if another box or sphere is collided with it.the bounding sphere you only define one vector the center of the sphere then you define a float value that is the radius of the sphere. the sphere class also has a intersect method. i prefer to use spheres beacuse they are easier to handle.in your case you'd defne the center of the sphere the models current position. i use a good way for collision detection that is i store the position of the model before actually calling the move function then if it collides then i make the current position equal to the previous position. here is some code // at the beggining of the game class BoundingSphere BSphere; BoundingBox BBox;//the other box that is going to be collided with
//define a new method private void CheckCollision() { if (BSphere.Intersects(BSphere)) { //the two spheres collided what to do currentMeshPosition = PreviousMeshPosition; } }
I hope that helped
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
He needs collision detection with complex terrain! Well, I guess you could use Newton, like I am trying now, but it has no samples for XNA that demonstrate how to use it properly :(
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
if what you are searching for is using terrain colision detection there s a custom content processor that makes you able to extract the vertex data i think its in ziggyware so you could use the Y component of the position as the height data then make the height of the camera equal to the Y of the vertex.
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
This may be a little more advanced than you are hoping for, but there is an article out there called the Plane-Sphere Sweep Test Algorithm. Here is the link to the actual paper written in 2003. It may seem complicated, but if you carefully read the article, it all makes quite logical sense. There is even C++ code at the end of the article to help you out. Here is another, more recent powerpoint presentation on the same topic. A while back I implemented this algorithm with success. It works quite well and should allow you to traverse over complex geometry. If it can help you at all, I wrote a small demo a while back (A tribute to Rainbow Six). It can be found on my site here: Source: http://users.accesscomm.ca/xnagaming/files/r6_tribute/Source.zipExe: http://users.accesscomm.ca/xnagaming/files/r6_tribute/Exe.zipIf you have any questions, I may be able to help you with some of the understanding. Feel free to e-mail me at: signot [at] gmail.com Good luck!
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
what about the XNA sample that has the ball rolling around on a mesh? I believe it simply sticks the mesh to the ground, no gravity or anything special.
XNA QuickStart Engine | My site"I'll be whatever I want to do!", Philip J. Fry
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
I don't quite think that's what he's looking for, Ikon. He has a plain old mesh that needs collision detection.
I've been having the same problem, and I've just given up on it. I have a large, varied terrain mesh, and I have no clue how to implement collision detection with it. So I've just restarted with a heightmap.
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
Ohhh. I actually spoke about the same thing with one of the guys on my engine project and he said you would need to have convex physics setup, and you'd need a way to cull out parts of the model that the entities are not close to. Basically it is very difficult to get a setup like that running....
XNA QuickStart Engine | My site"I'll be whatever I want to do!", Philip J. Fry
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
Why is collision detection so hard without BoundingBoxes/Spheres, seriously? I'm trying to add collision detection to some rocky terrain of mine, and it's really frustrating me.
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
@Signot: The paper you linked is very helpful, I'm currently working on implementing collision detection in a game of mine and it cleared up several of my questions. Hopefully your example code will clear up some more :).
I have a question though, and I'm hoping you or someone else on the forum can answer it. How would one handle the need for the different collision "responses" that can arise in a game when you start moving geometry itself? Ideally, I would like my collision detection to work like this:
Situation 1) Player runs into wall, is stopped. "Regular" response.
Situation 2) Player runs into some stairs, moves up the stairs. Handled in the article.
Situation 3) Player is standing still on top of an "elevator" tile. Elevator starts moving upward. I'm assuming that I would then be testing a swept box against a stationary ellipsoid, but I want any collisions to result in "fixing" the position of the player, not the elevator. Perhaps measuring the distance between the collision and the end position of the elevator, and applying that same translation to the player?
Situation 4) Let's say there's a "crushing wall" mesh. If the wall is moving horizontally, and the player is in front of it, it should push the player in the direction it is moving, similar to the elevator. However, if a second player is standing in the way, the first player should also push the second player - a chain reaction.
To handle this, I'd probably have to have multiple passes - Pass 1 would be movement of all player- and AI-controlled actors, Pass 2 would apply gravity to all applicable objects, and Pass 3 would move geometry objects. Pass 1 & 2 responses involve adjusting or stopping the movement of the actor against geometry, whereas Pass 3 assumes geometry is completely unyielding - if something gets in the way during that pass, you move the thing in the way instead of changing the geometry's vector. And, if you can't move the things in the way because of other geometry (e.g. the space between the crushing wall and opposing wall is smaller than the player) you "destroy" the thing that doesn't fit, or simply stop, depending on context.
It would also be nice if when one actor runs into another, you apply a small amount of your velocity into the other actor, giving the "running in place against another player slowly moves them out of the way" feel, which feels more natural than other players being immovable objects.
Has anyone put any thought into a system like this for a game they've designed, or seen an article that goes into some of the details of keeping track of what "kind" of velocity an object has, whether it's more or less immoveable than the thing it ran into, etc.?
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
Matt Sayar:Why is collision detection so hard without BoundingBoxes/Spheres, seriously? I'm trying to add collision detection to some rocky terrain of mine, and it's really frustrating me.
It isn't difficult against a heightmap terrain. You simply check the bottom of the box or sphere against the height of the terrain. Click the link to the template or engine in my signiture if you'd like some examples of this.
However, collision against models is a whole different story. Models can overlap, and rotate, and are dynamic. That is when you need a physics component to your game. That is when it becomes more difficult.
XNA QuickStart Engine | My site"I'll be whatever I want to do!", Philip J. Fry
|
|
-
|
|
Re: Collision Detection - How?n00b time
|
hey guys, thanks for all the replies!
All of your replies were very good, but I think Opelions hit the nail on the head, the only question I would have though, is what about bridges and such?
I've heard of raycasting collision detection, but I don't think that will work either, that's why I suggested newton, which, if anyone has any good tutorials/source code, please put it up, that would be nice.
thanks again, -Chris
|
|
-
|