Game Development Community

Enabled Thread

by Shane Cloutier · in Torque Game Builder · 06/13/2008 (3:42 pm) · 6 replies

Ok I'm trying to find out more about the Enabled field, I tracted it back from most torque objects to SimComponent. Turning it on and off so far seems to work like visable. It didn't turn off any behaviors, and I didn't check to see if it turned off collisions. Can anyone elaborate on what this field effects?

#1
06/13/2008 (3:45 pm)
It means whether or not the object gets updated or not. Plain and simple.
#2
06/13/2008 (3:59 pm)
So shouldn't that keep behaviors on the object from running?
#3
06/13/2008 (4:17 pm)
I'm not sure, I'll look into it for you. Have you tried disabling the behaviors on the object as well?
#4
06/13/2008 (4:23 pm)
Disabling an object disabled the behaviors attached. Are you experiencing otherwise? Which behavior are you using?
#5
06/16/2008 (11:54 pm)
I'm thinking it might have to do with me using schedule , I'm running a behavior similar to timerShoots.
Heres the code I came up with, I meshed timerShoots with faceObject. It allows me to fire at an object, say the player, without the object firing to turn to face the target. Disabling the object has stopped the rotation of the firing but not the actualy firing. So like I said I'm guessing its part of schedule wich I'm thinking I'll fix with an if statement.


//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

if (!isObject(ShootAtObject))
{
   %template = new BehaviorTemplate(ShootAtObject);
   
   %template.friendlyName = "Shoot at an Object";
   %template.behaviorType = "AI";
   %template.description  = "Set the object to shoot at an object";

   %template.addBehaviorField(projectile, "The projectile to clone and shoot", object, "", t2dSceneObject);
   %template.addBehaviorField(object, "The object to shoot at", object, "", t2dSceneObject);
   %template.addBehaviorField(fireRate, "The rate to fire shots (seconds)", float, "0.25");
   %template.addBehaviorField(fireRateVariance, "The variance in the fire rate (seconds)", float, "0.2");
   %template.addBehaviorField(projectileSpeed, "The speed of projectiles (world units per second)", float, "150");
   %template.addBehaviorField(turnSpeed, "The speed to rotate at (degrees per second). Use 0 to snap", float, 0.0);
   %template.addBehaviorField(rotationOffset, "The rotation offset (degrees)", float, 0.0);
   %template.addBehaviorField(trackingDistance, "The distance from the object to before it fires (not functional)", float, 150.0);
}

function ShootAtObject::onAddToScene(%this, %scenegraph)
{
   %targetangle = 0;
   %this.schedule(%this.fireRate, "fire");
   %this.owner.enableUpdateCallback();
}


function ShootAtObject::onUpdate(%this)
{
   if (!isObject(%this.object))
      return;
   
   %vector = t2dVectorSub(%this.object.position, %this.owner.position);
   %targetRotation = mRadToDeg(mAtan(%vector.y, %vector.x)) + 90 + %this.rotationOffset;
   %this.targetangle = %targetRotation;
}


function ShootAtObject::fire(%this)
{
   if (!isObject(%this.projectile))
      return;
   %position1 = %this.owner.position;
   %position2 = %this.object.position;
   %distance = t2dVectorDistance(%position2, %position1);

   
   %projectile = %this.projectile.cloneWithBehaviors();
   %projectile.setPosition(%this.owner.position);
   %projectile.setRotation(%this.targetangle);
   %projectile.setLinearVelocityPolar(%this.targetangle, %this.projectileSpeed);
   
   %min = (%this.fireRate - %this.fireRateVariance) * 1000;
   %max = (%this.fireRate + %this.fireRateVariance) * 1000;
   %random = getRandom(%min, %max);
   %this.schedule(%random, "fire");
   
}
#6
06/17/2008 (3:08 am)
Try adding this:

function ShootAtObject::fire(%this)
{
    if (!this.isEnabled())
        return;
   ...
}