Harvest
01-12-2007 13:09:56
Hi
What is the easiest way to implement trigger zones with ogreode? By that, I mean invisible cubes or cuboids that can be walked through and at the same time, detect a collision while being walked through to, for example, trigger some enemies to show up in a game.
thanks,
Harvest
Aquatix
01-12-2007 18:49:48
One way - create a box primitive (which is a trigger zone) and make it belong to nowhere (no collision space at all). Then, as your characters are moving around, check for their collisions with their rays (just one way) and voila - you've got it.
Harvest
01-12-2007 20:51:11
thanks for the quick reply. but unfortunately being the noob I am, I still need a more detailed explanation.
In a normal case, let's say, a wooden crate, I would:
-create a box primitive
-make it belong to .. the crate mesh? the entity?
-have collisions checked between the crate and my characters, so that they can't walk through it.
what exactly does "make it belong to" mean in ogreode code? this is, what's different between a concrete object and a invisible zone, right?
Harvest
01-12-2007 22:50:55
Is this passage here the "make it belong to" part, you were talking about?
//The usual Ogre Mesh Stuff
mEntity = mSceneMgr->createEntity("crate","crateCube.mesh");
mEntity->setQueryFlags (1<<2);
mNode = SceneMgr->getRootSceneNode()->createChildSceneNode("crate");
mNode->attachObject(mEntity);
mEntity->setNormaliseNormals(true);
mEntity->setCastShadows(true);
//The "make it belong to" part?
mBody = new OgreOde::Body(mWorld);
mNode->attachObject(mBody);
I did this in my app and a crate appeared in the air, where it should be. I attached it to a world with a standard gravity and gave it a mass. Then I added a stepper and a step/synchronize call in my main loop. I did nothing about collision, but:
If I set gravity to 1/100 of earth (0,0098...), my crate slowly moves down and lands on my plane. Why? I expected it to rush right through because I didn't say anything about collision handling.
If I set gravity to normal 9,81, the crate comes down so fast, I can barely see it - and it does NOT land on the plane. *?*
Sorry for offtopic, back to my first question, if this would be a trigger zone instead of a crate, then I would create a node without an entity, but with a body in shape of a box?
Aquatix
02-12-2007 01:16:04
Right, let me give it a try.
1) There is no need to do anything about the collision - that's the beauty, objects will collide as long as they are in the same world.
2) Your code is right, but did you create the Geometry part as well? Since a body only has a mass, yet it does not collide.
3) The problem with your gravity - if you use 1unit = 1meter, than gravity should be -9.87... If you use 1unit = 1cm, than gravity should be -987.0
4) If it is too fast, most likely the problem is with the stepper. You need to tell it about the time passed since last frame. That is in seconds (need to have a float there)
5) Back to triggers. It is really better if I can get some code, but I ain't got my machine atm. Well, if I remember well - the trigger zone is purely a piece of OgreOde::TriMeshGeometry (no Ogre::Entity, no OgreOde::Body). This trimesh is done with 0 world. As a result it never intervenes in your collisions. Why TriMesh and not Box? Well, your trigger zone is not always a box.
How would you collide with it, if it does not collide? Simple - you use if (OgreOde::RayGeometry::collide(someTriMesh)) {/*this unit entered the trigger zone*/} else { /*not triggered*/}
But before that, you have to use
Ray::setLength(something);
Ray::setDefinition(startingVector, endingVector);
Those two lines tell you where the ray must be (that is where your unit is standing, i.e. YourUnit::OgreOdeBody::getPosition()) But beware, do not run this every frame, as it is (the Ray::setDefinition() part) quite CPU hungry, so check for collisions with the trigger zone like once per second (and also check if the unit has moved at all).
Harvest
02-12-2007 11:32:59
thanks for the information and for correcting my wiki article as well, again, I learned a lot from that.
so this means, standard collision detection isn't something I have to bother with? if I create a wall, my character won't be able to run through it? just like that?
let's talk about the trigger zone issue, once you got your machine back

should be this week, right?
Aquatix
02-12-2007 13:25:53
Yeah, forget all the standard collision issues, they are all done automatically, that's the whole point of high-level physics engines. You are right, if you have a wall and try to run through it, you will not be able to. (just remember to include the line - mWorld->setContactCorrectionVelocity(1-2))
About the triggers that indeed will be beginning next week.
Harvest
25-12-2007 03:07:27
Aquatix, have you already had some time to look into this problem again? thanks
A trigger zone would have an ogre scene node and geometry by ode, but no ogre entity, is that correct?