Game Development Community

Getting projectiles to use Physical zones?

by David J Weaver · in Torque Game Engine Advanced · 12/23/2007 (8:25 pm) · 5 replies

So I was wondering if anyone has tryed this? I mean use Physical Zone to adjust the projectile just like it does the player, so if I have a projectile going at 100 m/s and it hits Physical Zone and Velocitymod is set at 0.5 it would travel at 50 m/s till it reached the other side of the Physical Zone and left at which point it would resume @ 100 m/s. Now I have scrounged around the forums trying to find anything on Physical Zone, and i have read over PhysicalZone.h and .cpp over and over and the only thing I could even think of was:


And this is in projectile.cpp

const U32 Projectile::csmDynamicCollisionMask = PlayerObjectType |
VehicleObjectType |
DamagableItemObjectType;


I tryed to add PhysicalZoneObjectType but im currently having some issues with sceneObject.cpp giving me some wierd error about "Whoa thats too much" or something, so TGEA only runs for about 5 projectile launches and then crashes. When I was shooting I was pretty sure it was not doing anything though and I think that the answer is a bit more complicated.

So could anyone give me a pointer in the right direction on this? And later I want to slow down "everything" that enters a phsical zone, but that's later.

Also the TDN is pretty bare on Physical Zones.

#1
12/27/2007 (12:02 pm)
Ok so I have still been playing with this, and this is CONFUSING!
So I added A collision mask just for Physical Zones inside Projectile.cpp
so i have added everything i needed to make sure i could turn it off in projectile.h and everything i needed to send it to other players in Projectile.cpp but this is where im running into problems...

I dont know where to do the math, here ill explain..

void Projectile::processTick(const Move* move) 
  { //bunch of code cut out....
  oldPosition = mCurrPosition;
   if(mDataBlock->isBallistic)
      mCurrVelocity.z -= 9.81 * mDataBlock->gravityMod * (F32(TickMs) / 1000.0f);
   if(mDataBlock->isPhysical)// here is where im running into problems... im drawing a blank

Or maybe the math goes down farther near

// Determine if the projectile is going to hit any object between the previous
   // position and the new position. This code is executed both on the server
   // and on the client (for prediction purposes). It is possible that the server
   // will have registered a collision while the client prediction has not. If this
   // happens the client will be corrected in the next packet update.
   if (getContainer()->castRay(oldPosition, newPosition, csmDynamicCollisionMask | csmStaticCollisionMask | sCollisionMoveMask, &rInfo) == true)
   {
      // make sure the client knows to bounce
      if(isServerObject() && (rInfo.object->getType() & csmStaticCollisionMask) == 0)
         setMaskBits(BounceMask);

I added sCollisionMoveMask and defined (sorry if thats the wrong terminology) it up top I also made sure to #include "PhysicalZone.h"

What ive been doing is looking over player.cpp and Projectile.cpp to see where i can throw in the mAppliedForce, mGravityMod and mVelocityMod, but im completly stuck when it comes to doing crazy Game math. Can someone help me please?
#2
12/27/2007 (12:18 pm)
In the player.cpp there's a spot where it says "apply force from physical zones" or some such. You should probably just take that and move it into the projectile class at an appropriate spot. As I recall though, you'll need to make it so it can rotate as well.
#3
12/27/2007 (1:31 pm)
Yeah this:
// Add in force from physical zones...
   acc += (mAppliedForce / mMass) * TickSec;


but its not quite that easy.. Players use Player::updateMove to control them but projectiles dont, they use Projectile::processTick, which looks like its time based ( please inform me if im wrong, i only know what i have taught myself) Players have some code that checks to see what they ran into (because thats what players do) but Projectiles only need to know if they ran into something damagable or not, and if so, go boom.... at least thats how i see it.
#4
12/27/2007 (1:41 pm)
No, its Tick based as it gets updated by the server which updates only once per tick.
updateMove is time based, therefor the TickSec factor.

but you are right, you would most likely need to modify the physical zone as well to apply a force to a projectile so above equation actually adds something to the acceleration.
#5
12/27/2007 (9:32 pm)
I also found this in player.cpp

// Take into account any physical zones...
      for (U32 j = 0; j < physZoneCollisionList.count; j++) {
         AssertFatal(dynamic_cast<PhysicalZone*>(physZoneCollisionList.collision[j].object), "Bad phys zone!");
         PhysicalZone* pZone = (PhysicalZone*)physZoneCollisionList.collision[j].object;
         if (pZone->isActive())
            mVelocity *= pZone->getVelocityMod();


1 step closer, and 3 steps back. I had to comment out all of my code because im getting some REALLY wierd errors from TGEA, like from pathManager.cpp its crazy. If I get it working ill post here.