Why won't this shoot?
by Robert Carroll · in Torque Game Builder · 11/17/2009 (9:20 pm) · 4 replies
Hi, this is one of the first behaviors I've modified.
====
I just can't get it to fire the projectile.
====
I just can't get it to fire the projectile.
if (!isObject(SMouseShootsBehaviorAdv))
{
%template = new BehaviorTemplate(MouseShootsBehaviorAdv);
%template.friendlyName = "Mouse Shoots Behavior Adv";
%template.behaviorType = "Game";
%template.description = "Shoots an object when mouse down";
%template.addBehaviorField(projectile, "The projectile to clone and shoot", object, "",
t2dSceneObject);
%template.addBehaviorField(fireRate, "The rate to fire when the fire key is held down (seconds)",
float, "0.25");
%template.addBehaviorField(projectileSpeed, "The speed of projectiles (world units per second)",
float, "150");
%template.addBehaviorField(fireAngleOffset, "Direction of motion angle offset relative to the owner's
rotation (degrees)", float, "-0");
%template.addBehaviorField(rotationOffset, "Rotation offset of the projectile itself relative to the
owner's rotation (degrees)", float, "-0");
}
function MouseShootsBehaviorAdv::onBehaviorAdd(%this)
{
%this.tryingToFire = false;
if (isObject(moveMap))
}
function MouseShootsBehaviorAdv::onBehaviorRemove(%this)
{
if (isObject(moveMap))
}
function MouseShootsBehaviorAdv::fire(%this, %val)
{
%this.tryingToFire = %val;
if (%val == 0)
{
cancel(%this.fireSchedule);
if( !isEventPending(%this.waitSchedule))
%this.waitSchedule = %this.schedule( %this.fireRate * 1000, "fireCond");
return;
}
if (isEventPending(%this.fireSchedule) || isEventPending( %this.waitSchedule))
return;
if (!isObject(%this.projectile) || !%this.owner.enabled || !%this.owner.getVisible())
return;
%projectile = %this.projectile.cloneWithBehaviors();
%projectile.setPosition(%this.owner.position);
%projectile.setRotation(%this.owner.rotation + %this.rotationOffset);
%projectile.setLinearVelocityPolar(%this.owner.rotation + %this.fireAngleOffset, %
this.projectileSpeed);
if (!isEventPending(%this.fireSchedule))
%this.fireSchedule = %this.schedule(%this.fireRate * 1000, "fire", 1);
}
function MouseShootsBehaviorAdv::fireCond(%this)
{
if( %this.tryingToFire )
%this.fire( %this.tryingToFire );
}About the author
Stay Up all night playing PS3 ;) add me PSN: RCBASEBALL13.
#2
11/19/2009 (12:47 pm)
Did you attach the behavior? Do you have a projectile defined? I have to assume you do but starting at the basics and looking them over is always the way to start.
#3
11/19/2009 (6:54 pm)
Echo() also helps. A LOT
#4
11/20/2009 (2:24 am)
I'm guessing your object can't fire because you didn't attach the behavior to the object. The line "if (isObject(moveMap))" will not compile.
Milan Rancic