Problem with raycasts

daedar

21-05-2007 09:41:42

Hi,

here is my code for a raycast (to get the closest actor, after a bullet shot):

NxOgre::RayCaster caster = NxOgre::RayCaster(pos, dir, length, NxOgre::RayCaster::RCT_CLOSEST, nxScene);
if( caster.castShape(NxOgre::RayCaster::AF_NONE) )
actor = caster.getClosestActor();


Sometimes, actor is NULL whereas I really got an actor targeted and closest enought to be < length (and when this happens, nearlly every raycast after that fails). What's really strange is that even when actor is NULL, caster.getClosestRaycastHit().mActor can be != NULL :shock:

All I've got in my world for the moment are static geometries...

Any idea?

Thx a lot

betajaen

21-05-2007 10:03:31

Did you normalise the direction?

direction = direction.normalisedCopy();


You should also create the class in the proper way:

NxOgre::RayCaster caster = new NxOgre::RayCaster(pos, dir, length, NxOgre::RayCaster::RCT_CLOSEST, nxScene);

daedar

21-05-2007 12:12:12

Did you normalise the direction?

Indeed, it works better with a normalised direction vector!

Thx again betajaen and sorry for the newbie question.