XNA Game Development Forums
2012/05/18 06:36:26 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Climbing stairs with collision detection  (Read 3787 times)
internetking
Newbie
*
Offline Offline

Posts: 3


View Profile
« on: 2007/03/14 12:19:28 »

Hi,
 I really need help here. I'm writing a game for my project with XNA and I've followed the tutorials here and it has been of great help. I need to know how to do three basic things
1. Detect collision between objects - I have a large city with a few humans. The houses are very detailed with doors and fences and stuff
2. What logic do I use to open the doors:
    Do I attach door as part of the models or I used have it as a separate model.
2. I want to know how to climb stairs- I'm using a 3rd person camera and I have no idea how to implement this. I really need some references.

Any code, suggestions and references will be greatly appreciated as I've really run out of time.

Thank you.
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #1 on: 2007/03/14 15:53:04 »

The door operation could be done in a couple of ways, both of which would probably use some sort of scripting type activity. When a player (or human in the level) walks up to or does the 'activate' action on the door (which would be an action built into the scripting engine) an animation would trigger (tiggers would also be built into the scripts). With the scripting the door could be a separate object with a simple rotate animation or an object where the animation is only the door part moving. Those are just the ways I can think of off the top of my head, but there are I'm sure many other ways to do this.
Logged
Nercury
Newbie
*
Offline Offline

Posts: 8


View Profile
« Reply #2 on: 2007/03/16 07:10:44 »

This tutorial may be usefull to get basic collision ready (it also discusses octrees in the end): http://www.flipcode.com/articles/article_basiccollisions.shtml

Object you are moving should have some sort of acceleration down (gravity), and acceleration to direction it is moved. Real direction would be these two acceleration vectors added together. Object stops when colided only if movement vector is close to perpendicular to surface (otherwise it should slide along the surface), so obejct can stand still on nearly flat surfaces when not moving.

For stairs, i imagine, after collision is detected you could check if object would colide if it would be in higher position (Z+MaxStairHeight (or Y+MaxStairHeight in HM engine)), and if not, move it there + move it down on the surface. There is no reason to check for movement downstairs, because gravity should do the job. That would be very simple, not smooth, way to implement this, because object would "jump up" with every step up.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #3 on: 2007/03/16 17:51:16 »

Stairs are usually implemented where their collision mesh is just a ramp to allow smooth movement up, and the stair mesh looks like the stairs. Players will not notice that the avatar is moving up a ramp rather than stairs if you keep the collision mesh touching the edge of the stairs. That way its not a jerky movement, and also a simpler shape for collision checking.
Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #4 on: 2007/03/16 18:39:51 »

Quite often the best way to use ramps with stair meshes is to position the ramp inside the actual steps so that the feet of the model seem to at least be somewhat stepping ON them instead of above them. Image attached for clarity Smiley In this model the stair mesh itself isn't even collidable. (You could also just fudge with the stair bounding box to make the ramp part there, but using a separate bounding plane seems easier)

[attachment deleted by admin]
Logged
internetking
Newbie
*
Offline Offline

Posts: 3


View Profile
« Reply #5 on: 2007/03/18 10:23:38 »

Hi guys,
 Thanks so much for the response. I've taken a look at the various references and I'm not having an easy time at all understanding them. From the look of things, I have to set the steps and the doors as separate meshes. Then when I detect collision with them, I can run the door animation for opening the door or move the character up the ramp.
 I guess the first real problem is the detection of the collision before considering how to detect the current height of the ramp. I've read countless tutorials but none of them are straight forward.

 Assuming I've loaded two models (model1 and model2), how do I detect collision between them?

Thank you.
Logged
Nercury
Newbie
*
Offline Offline

Posts: 8


View Profile
« Reply #6 on: 2007/03/18 15:09:31 »

Doing Mesh vs Mesh collision detection in managed code is quite an overkill for any bigger project. I assume you have your "character" which should move around, and if so, it is probably even animated. That means you have to do collision detection almost frame-by-frame, and that, IMHO, WILL kill FPS.

Now lets look at things which were already done. For example, games written in C++. They do not detect collision between visible meshes, but ussualy use some kind of optimisation. For example, Unreal2 engine games uses cylinder around players (HalfLife2 engine - infamous simplified colision mesh). Players ussualy move on three surface types: terrain, BSP geometry, and meshes. For terrain, players are "glued" to it when not jumping. BSP is basic sculpting tool (which can be used to make basic shapes of buildings, etc), and contains small amount of polygons (in other engines it could be mesh). And finally, there are StaticMeshes, which are used for decoration. Furthermore, artists ussually make simplified collision mesh almost for every static mesh, which most of the time happens to be box. And this is for C++ game.

I am not saying that this is the way it should be done Smiley. But for simple game or project cylinder (or box, or few boxes) around model should be fine. I am sure that Mesh Intersect function WILL be included in later XNA version. However, in such case simplified collision would help to achieve even higher FPS Smiley

Now, how to detect that simplified mesh... I looked around a little and so far i found this solution, to collect information about mesh part by drawing vertices as points while writing info about that somewhere. Also, i don't know if you already saw this, but someone is writing XNA tutorial exactly for doing that. I am going to look at his custom processing tool when i have more time.

For doors, there is one more way to make them work - place object "Trigger" there, which will make them open when character enters specified radius (or cylinder), and close when he exits it.

Well, sorry for not posting any real sollution, but maybe some info will be usefull...
« Last Edit: 2007/03/18 15:35:38 by Nercury » Logged
internetking
Newbie
*
Offline Offline

Posts: 3


View Profile
« Reply #7 on: 2007/03/19 12:24:32 »

Hi,
 Thanks so much for the response. I haven't replied because I was looking through all the materials that were posted. I've found out that the easiest and yet least effective of the collision detection is the spherical methods if the model is represented with one sphere. The collision is not perfect but it appears fast enough. I'm planning on adding a bounding sphere for each model and adding a few methods to check for collision. Since I have so much to do and so little time (I have to submit before the first week of April), I will settle for the spherical method.

The idea is that if the distance between the two vertices is less or equal to the sum of the radii, there is collision.

I'm currently adding events to be raised if there is collision. I'll post some pictures and the output.

I'll get to the stairs problem after the collision is done.

Thank you again.
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #8 on: 2007/03/19 16:32:35 »

Fitted bounding elipsoids are a bit better and not too much worse code wise than spheres. Once you get spheres working you might want to add a second level with those or just replace spheres with them in the working model Smiley and afterwards... HIERARCHICAL SPHERE TREES!!! Wink
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Terrain Traversing/Collision Hazy Mind XNA Engine Quinn 1 1604 Last post 2007/02/28 00:27:04
by Ardman
Detecting Model Collision...? General Discussion « 1 2 » DaphydTheBard 15 4277 Last post 2007/03/27 01:29:52
by Nemo Krad
Has anybody managed to get some collision in the game? Hazy Mind XNA Engine Jonotron 5 2114 Last post 2007/06/19 01:22:35
by Nemo Krad
Mouse selection (collision?) Hazy Mind XNA Engine Requests Zan 2 2696 Last post 2007/05/19 16:32:50
by Zan
3D Collision Detection and Physics General Discussion « 1 2 » LucianX 15 4648 Last post 2007/08/02 20:54:38
by mikeschuld
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.082 seconds with 18 queries.