Collisions with meshes.

brads55

Member
Joined
Aug 1, 2005
Messages
6
Location
North Yorkshire, UK
Ive got a program that uses managed directx and Ive got a robot moving around an arena, I need of detecting collisions with walls so I can stop it going through them. The problem is I dont really know how to do it. Ive tried methods like Mesh.Intersect, but it didnt work, (I dont think I understood it). Any help would be appreciated.

Brad.
 
Overview:
Can use inner/outer boundary box.

Outer detects collisions for outer walls of a room.

Inner detects collisions which take place when charactor comes acrossed an object in the room, such as another charactor, or table.

Simple Rules:
Movement should be restrained so as not to allow charactor to cross over an
object in a room.

Charactor should not be able to move past outer walls.

Boundary Box:
Setup an imaginary box, then type in coordinates, eg. upper/lower/left/right borders and if charactor comes near, do not allow it to pass, yet allow it the ability to move in other directions as long as it doesnt come across another boundary.

4 direction charactor movement outer boundary detection:
Take for instance you move charactor up, your upper boundary for the rooms back wall is at Z+ (12.0F) your charactor should not pass 12.0F, and no longer be given ability to move up once the upper bound has been reached, yet the charactor should be allowed to move left, right, or down.

All 4 directions must be treated this way.

Inner boundary detection:
Your charactor should not pass the boundary of another object in the room, yet should be allowed to move around the object.

For example:
Object is at center of room, the right side of the object is boundary X+ (1.0F), if your charactor moves towards the left, it should no longer be able to move once the charactor reaches the right boundary of the object in the room. Yet, the charactor should be allowed to be able to move up, down, or right.

Do test for each direction your charactor moves.

Basically you are comparing your charactors position with that of the defined object boundaries.

Testing multiple objects in room:
Store a list of boundary structures for each object in the room/level, everytime the charactor moves in any given direction, check each boundary value in the list to see if a collision has happened.

Projectile:
Lets say we want to fire projectile at object in room, you want it to test for boundary collisions the same way as if it were the charactor moving, when the projectile reaches an objects boundary, have it perform some action.

To return which object was hit by the projectile, simple return the name of the object that is linked to the boundary that was hit.

Charactor interaction/menu activation:
If you were playing an RPG youd know that when your charactor comes face to face with another charactor or object in the scene, a menu may popup or charactor dialog, so how is this done?

Simple, the same as with the other methods, when your charactor comes accross the boundary of another object, a message can be displayed then to indicate further action, for example:

Your charactor moves up and hits the lower boundary of a genie, the genie asks you what you wish, you give keyboard or mouse input to make your choice, then you go from there.

Well, hope all this has made some sense so far, goodluck!

:cool:
 
Last edited by a moderator:
Thanks. I think Im going to use a set of bounding boxes, and test for collision. But how do you test to see if two 3D cubes are intersecting? The data I have for each cube is the two opposite vector3s needed to calculate every vertex. (left, bottom, closest) and (right, top, farthest).
 
Ignore the Y for now assuming the Y Axis is up until you become familiar with the concept to do more complicated detection.

Its as simple as this.

Lets say your back wall in a room is as Z+ (12.0F), the front wall is at Z- (-12.0F), your charactor can move forward or backwards along the Z Axis as long as its between Z+ (12.0F) and Z- (-12.0), allow charactor input of the direction you are moving until you get to the boundary.

Example:
Charactor has now moved up until it reached Z+ (11.0F), the input for charactor moving forward is now disabled, so any time you press the up arrow key to move forward the charactor will not move forward, thats it!

The reason we stopped at Z+ (11.0F) instead of Z+ (12.0F) is we assume the charactor has a size of (1.0F), now the size of your geometry will vary so youd have to adjust bounding calculations for that.

It helps to visualize this data in realtime, so display the vector position of your charactor (X,Y,Z) in the forms title text and compare to bounding box of your rooms walls.

Adjust collision detection to match how the charactor responds when it reaches certain points, if for instance the charactor gets stuck, you need to adjust detection a bit to allow movement but restraint direction where collision happens.

Later on when you get more comfortable with this, for walls inside a room, such as for a hallway, you create inner bounding boxs that make up the sides of a wall.

Ive added some pictures to help visualize what Im saying, the lower box is the main charactor, upper box is another charactor or object in the room, the red lines show the walls, the ones with arrows show movement, the cross is projectile, but I also use it for making manual boundary calculations.
 
Last edited by a moderator:
The bounding box values are updated and based on the position of the moving object, thus, the bounding values for any moving object is variable, meaning it changes.

If the object moves right to X+ (1.0F) and the object was originally at X (0.0F) then update the bounding information to reflect the current position, the objects right boundary would now be X+ (2.0F) instead of X+ (1.0F).

You only need to update the values for moving objects, but the comparison remains the same regardless of weither object is moving or not, just remember to update the bounding values of all 4 boundaries when object is moved.
 
Back
Top