Game Development Community

ProjectileObjectType problems

by janet kim · in Torque Game Engine · 04/24/2005 (5:29 pm) · 6 replies

I'm trying to use a container raycast to get particles to detect projectiles and interiors. Currently, the particles have no problems bouncing off of objects of type InteriorObjectType, but for some reason, I can shoot a large projectile (ProjectileObjectType) with a collision mesh right through them and ...nothing. Is there something that I'm missing specific to projectiles? Any help would be happily appreciated!!

This is my bounce function in particleEngine.cc:

bool PEngine::bounce( const Point3F &nextPos, Particle *particle, const U32 t, ParticleEmitter &emitter )
{
   F32 radius = 10;
   Point3F curPos = particle->pos;

   Point3F dir = nextPos - curPos;
   if( dir.magnitudeSafe() == 0.0 ) return false;
   dir.normalizeSafe();
   Point3F extent = nextPos + dir * radius;
   F32 totalDist = Point3F( extent - curPos ).magnitudeSafe();
   F32 moveDist = Point3F( nextPos - curPos ).magnitudeSafe();
   F32 movePercent = (moveDist / totalDist);

   RayInfo rayInfo;

	U32 collisionMask = ProjectileObjectType | InteriorObjectType;

	if( gClientContainer.castRay( curPos, extent, collisionMask, &rayInfo ) )
	{
		Con::printf("particleEngine::bounce! detected %s", rayInfo.object->getClassName());

		Point3F reflection = particle->vel - rayInfo.normal * (mDot( particle->vel, rayInfo.normal ) * 2.0);
		particle->vel = reflection;

		Point3F velDir = particle->vel;
		velDir.normalizeSafe();

		Point3F bouncePos = curPos + dir * rayInfo.t * movePercent;
		bouncePos += particle->vel * t;

		particle->pos = bouncePos;

		return true;
	}
   return false;
}

#1
04/24/2005 (11:44 pm)
Maybe Projectile doesn't implement castRay?
#2
04/25/2005 (9:26 am)
Aha - so anything that doesn't have a castRay function will not be found by a container ray search? I.e. Trigger formerly could not be detected because it had no collision mesh, but a castRay function was added so now it can? Yikes, getting confused. What's the relationship with castRay, collision meshes, container castRay...? Just trying to get this all straight!
#3
04/25/2005 (9:36 am)
Ok - I've implemented a rayCast method for Projectile and now it is being found!
#4
04/25/2005 (3:16 pm)
Cool beans.

(Basically, each object is responsible for implementing its own collision detection primitives; castRay is the one responsible for... gasp... ray casts. Projectile doesn't implement this by default because it wasn't needed for Tribes2.)
#5
08/21/2005 (8:52 pm)
I just used this article to help me get triggers working with projectiles. It also gave me some more insight into the engine. Basically your object (projectile, item, whatever) is responsible for implementing functions like castRay and buildPolyList itself. When a projectile checks for collision against other objects, it calls the other object's castRay function. If it doesn't have one this will return false and the projectile will not register a collision with the object. Therefore, if you want a projectile to register a collision with a trigger, you have to implement a castRay function on the Trigger.

See this thread: http://www.garagegames.com/mg/forums/result.thread.php?qt=28891

You will also have to make sure the projectile collision masks are set up right and then once you register a collision with a Trigger Type, you then need to add

Trigger* pTrigger = static_cast<Trigger*>(rInfo.object);
           pTrigger->potentialEnterObject(this);

Afterwards, the potentialEnterObject function will try to see if the projectile is inside the trigger. It will do this by calling the projectile's buildPolyList function. However, projectiles do not implement this function so it will return false and the trigger will not think the projectile has entered it. You need to implement this function for the projectile. I just copied Item's buildPolyList implementation.

Hope this helps.

P.S. correct me on any mistakes, i'm pretty new to all of this.!
#6
09/22/2005 (7:23 pm)
Could you possibly go into a bit more detail as of how you got triggers working with projectiles?

I've been trying to accomplish the same thing but haven't had the luck (well, not luck) you seem to have had. It's probably partially due to the fact that I don't know the engine hugely well yet... but even in learning more about it (as I am trying to do so so i can accomplish this) i still seem to be coming up short.