NxOgre Collisons questions

Springare

13-01-2008 13:24:41

hi im working on a tank game whit 2 friends but I have some problems whit the collison.

what I want to do is when a tank shoot collieds whit the terrain (whitch is a trianglemesh) it will just explode and show a nice patrical effect and play a sound. When it collieds whit a tank it shall do the same as the terrain but it shall add alittle force on the tank and change some variables.

the problem is that I have made all tanks to be in the actror grp "pTank_ActorGrp", the tank shot in "pTankShot_ActorGrp" and the terrain is in the "pTerrain_ActorGrp"

so far I am whit you, but I get lost whit all this callback classes. Could any1 maybe, if they got time, explain it a little more. Like what they actualy do and where I shall make the class (in a new .h .cpp file or just add it to some other files) and how I can see when an actorgrp collileds whit a speccific actorgrp.

I have been following this guide : http://www.ogre3d.org/phpBB2addons/viewtopic.php?p=27130#27130

but as I said, the callback is abit blurry ^^

cheers & thanks advance
//Springare

NickM

13-01-2008 19:39:20

To be honest it's quite clear in that thread you linked to, what exactly is confusing you?

Springare

13-01-2008 20:19:39

I don't really know where to make the class and where I write the code for what happans when a pTankShot_ActorGrp collide whit a pTank_ActorGrp.

NickM

14-01-2008 06:52:58

I'm quite new to programming too but I am learning :)

One way is to create your own callback class that inherits from 'NxOgre::GroupCallback::InheritedCallback' (A look at this thread may help http://www.ogre3d.org/phpBB2addons/view ... 33cbc37555 )

Then depending on when you want to detect the collision you put your code within 'onStartTouch' 'onEndTouch' or 'onTouch'

For instance I use 'onTouch' and within there I get the force of the contact, if it's above a certain level I find which one of my objects is in collision by looking its name up in a mapped list, once I have my object I can call whatever method I want within that object ie: object->simulateExplosion()

Hope that helps a little.

Springare

14-01-2008 11:55:03

okey thanks ^^ I think I'm on the right track now but none of onStartTouch, onEndTouch, onTouch want to run. the shot is just bounching around the map even tho I have put a brake in side the onStartTouch to see if it is runned at all...

this is the code for the groups:

pTankShot_ActorGrp = pNxScene->createActorGroup("TankShotGrp");
pTank_ActorGrp = pNxScene->createActorGroup("TankGrp");
pTerrain_ActorGrp = pNxScene->createActorGroup("TerrainGrp");
mTankShotCallback = new tankShotCallback();
pTankShot_ActorGrp->setCallback<tankShotCallback>(mTankShotCallback,&tankShotCallback::onStartTouch,&tankShotCallback::onEndTouch,&tankShotCallback::onTouch);
pTankShot_ActorGrp->setCollisionCallback(pTerrain_ActorGrp, NX_NOTIFY_ALL, true);


I even tried whit
pTerrain_ActorGrp->setCollisionCallback(pTankShot_ActorGrp, NX_NOTIFY_ALL, true);
pTank_ActorGrp->setCollisionCallback(pTankShot_ActorGrp, NX_NOTIFY_ALL, true);


this is the callback class:

class tankShotCallback : public GroupCallback::InheritedCallback
{
public :
tankShotCallback()
{

}

void onStartTouch(Actor *a, Actor *b)
{
// I had my break here
}

void onEndTouch(Actor *a, Actor *b)
{


}

void onTouch(Actor *a, Actor *b)
{

}


this it the code for the tankshot and the terrain:
pShotBody = m_pNxScene->createBody("TankShot.mesh", new CapsuleShape(15, 35), Vector3(0, 500, 0), "mass: 5 Group: TankShotGrp");
Body *pBody = m_pNxScene->createBody(m_sMeshName, new TriangleMeshShape(m_sMeshName), Vector3(0.0f, 0.0f, 0.0f), "static: yes Group: TerrainGrp");

any idea for why the callback calles won't run?

betajaen

14-01-2008 11:57:13

static: yes Group: TerrainGrp

Goes:

static: yes, Group: TerrainGrp

(Note the comma)

Springare

14-01-2008 12:04:54

Wohooo it finaly works <3 thanks all for the help :P now I just need to figure out the code to remove the etire ShotBody of the shotactor who collides and to play an explosion animation heheh. but thats another story

("\(^-^)/") Big hug to NickM & betajaen