Game Development Community

Projectile field values dissapearing between creation and onCollision

by Justin Campbell · in Torque 3D Professional · 08/02/2009 (6:47 am) · 1 replies

I am working with an almost completely default T3D Beta 4 project (modifications only to the player.cs). I am attempting to keep score with the incScore but I am getting errors from a null object upon player or bot deaths. Tracing down the problem seems to indicate that the root cause is between the onFire and onCollision event somehow the projectile is loosing the sourceObject field value. Once the projectile object is created, I check the source object field value and it is there. Then upon the oncollision event (for the same projectile) I check again and it is not there (i.e. null). This happens about 60% of the time. Below I have posted the modified crossbow.cs and some of a console session. Could someone help me dig deeper into this issue?

I would happily call this a bug if I knew the code between the chair to keyboard interface wasn't flawed.

function CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   // Apply damage to the object all shape base objects
   if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
      %col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");

   // Radius damage is a support scripts defined in radiusDamage.cs
   // Push the contact point away from the contact surface slightly
   // along the contact normal to derive the explosion center. -dbs
    //%obj.dump();
    error("4 " @ %obj.getfieldvalue(sourceObject) @ " is the collision object passed.");
    error("5 This is the collision projectile " @ %obj.getid());
        //%obj.getfieldvalue(sourceObject)
   radiusDamage(%obj.getfieldvalue(sourceObject), %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
   //radiusDamage(%obj, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
}

function CrossbowImage::onFire(%this, %obj, %slot)
{
   %projectile = %this.projectile;

   // Decrement inventory ammo. The image's ammo state is update
   // automatically by the ammo inventory hooks.
   %obj.decInventory(%this.ammo,1);

   // Determine initial projectile velocity based on the 
   // gun's muzzle point and the object's current velocity
   %muzzleVector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   %muzzleVelocity = VectorAdd(
      VectorScale(%muzzleVector, %projectile.muzzleVelocity),
      VectorScale(%objectVelocity, %projectile.velInheritFactor));

   // Create the projectile object
   %p = new (%this.projectileType)() {
      dataBlock        = %projectile;
      initialVelocity  = %muzzleVelocity;
      initialPosition  = %obj.getMuzzlePoint(%slot);
      sourceObject     = %obj.getid();
      sourceSlot       = %slot;
      client           = %obj.client;
   };
   MissionCleanup.add(%p);
    error("1 This is the source " @ %obj.getid());
    error("2 This is the written source " @ %p.getfieldvalue(sourceObject));
    error("3 This is the source projectile " @ %p.getid());
    
   return %p;
}

selected results from console.log
//Here is an example of good behavior
1 This is the source 2791
2 This is the written source 2791
3 This is the source projectile 3435
4 2791 is the collision object passed.
5 This is the collision projectile 3435
//Here is an example of bad behavior
1 This is the source 2791
2 This is the written source 2791
3 This is the source projectile 3471
4 0 is the collision object passed.
5 This is the collision projectile 3471

#1
08/02/2009 (12:07 pm)
Unfortunately this is how the projectile class has always worked in Torque. The "source" parameter is deleted about 7 ticks into the projectiles flight.

You can "store" the client as a dynamic field for the projectile object and then check for that field when the projectile collides/explodes.