Cube collision query for Crate

nikki

26-11-2006 19:23:39

In my game, there is a Crate which the Player can push around. Previously, I made this Crate a rigid body, so that it could be pushed around. But, I realised that it was too realistic, because the Crate needed to move one grid unit (in other words, 'jump' to the next cell-space, like in Chip's Challenge). For this, I made it a static object (a Geometry without a Body). When it collides with the Player, it moves accordingly. I've got it all working, but there are two problems:-

1. It moves into walls.
2. It is does not fall down if there is no floor under it.

All this can be fixed with a cube collision query (place a cube geometry at a position, and check if it collides with anything). To solve the first problem, we do a cube query with the new position, and move if it does not collide. Here is an image (brown = crate, dark gray = wall/floor, light gray = query, green = a little obstacle):-


As for the second problem, we do a cube query one unit under the Crate and fall if there is nothing there.

Regarding alternatives:-

We could do a ray query, but it will not work for the green obstacle example above (of the ray is shot from the head or foot of the Crate).
I also tried moving back if there is a collision, but the space we have to move back to is occupied by the Player, and this method doesn't work for falling.

My question (at last) :) :-
How do I do a cube query (like Ogre's BoxSceneQuery)?

nikki

28-11-2006 03:11:51

Ok, second question:-
How do I check whether there is a collision between a Geometry and the other Geometries in its Space?

tuan kuranes

29-11-2006 14:31:19

A Geometry class is the way to make "queries".

We could do a ray query, but it will not work for the green obstacle example above (of the ray is shot from the head or foot of the Crate).
make the static geometry "cube" query being a "cube" that include both start position cube + end Position cube.

How do I check whether there is a collision between a Geometry and the other Geometries in its Space?
make this geometry being inside its own Space, the call
myGeometrySpace->collide(otherSpace);

nikki

30-11-2006 07:09:41

Ok, I got half of it. First, I will make a new Space, called querySpace. Then, I will make a BoxGeometry whenever the Crate has to move. This Geometry will be in the new Space. I will put this BoxGeometry at the position where the Crate has to move to. Then I will call:-
querySpace->collide(physicsWorld->getDefaultSpace());
But, it seems that this function has a void return value. Is there no function that has a bool return value, or a real return value, telling how many collisions are there, or whether there is a collision? If there is, it will be easy, for example:-
bool notEmpty = queryGeom->collide(otherSpace);
if (!notEmpty)
//move the crate here.

Otherwise I have to add more things in the collision listener etc.

Second question: What actually happens if I return 'false' in the collision listener's collision() event?

Thanks for the help! I really appreciate it. :)

tuan kuranes

30-11-2006 09:02:24

But, it seems that this function has a void return value. Is there no function that has a bool return value, or a real return value, telling how many collisions are there, or whether there is a collision?
That's what the collision callback mechanism is for.
Second question: What actually happens if I return 'false' in the collision listener's collision() event?
Collision do not happen.

nikki

30-11-2006 16:44:34

Ok, I fixed it. I wrote a little funtion and a GameObject that will allow me to do queries easily. This is part of my Crate's collision function (move is the Vector3 the Crate has to move by):-
OgreOde::Geometry *query = new OgreOde::BoxGeometry(Vector3(9.99,14.2,9.99), GlbVar.querySpace);
if (createCollisionQuery(mNode->getPosition() + (move * 0.5), Quaternion::IDENTITY, query))
return true;
//Crate moving code goes here

Easy, isn't it? :)