How would I get this to shoot at me?
by Robert Carroll · in Game Design and Creative Issues · 08/18/2009 (1:52 am) · 5 replies
I just got TGB and was wondering how to get this thing to shoot at me? I saw the game saple of a shooting ship thing and they had these thing's that rotate and shoot me?
About the author
Stay Up all night playing PS3 ;) add me PSN: RCBASEBALL13.
#2
08/19/2009 (5:16 am)
It is exactaly what I needed but i cant get it to shoot or face me and i set it to face "player" and set the projectile to "missle" is therse something i need to edit like the missle?
#3

pShip is the player(ship). projectile1 should be a static sprite and and projectileEff1 a particle effect. The turret should face the player with these settings, but I'm just not sure if I didn't use a separate behavior for the shooting part. I just don't have the time to get deeper but I hope this helps already.
08/19/2009 (8:02 am)
These settings should work with the shooter example:
pShip is the player(ship). projectile1 should be a static sprite and and projectileEff1 a particle effect. The turret should face the player with these settings, but I'm just not sure if I didn't use a separate behavior for the shooting part. I just don't have the time to get deeper but I hope this helps already.
#4
08/19/2009 (4:29 pm)
Ok now I got it to face me but it dosnt shoot at me. But i cant get the shoot advanced behavior from the sample game to shoot ethir dose it have something to do with scripthing the projectile?
#5
If you set the class of the projectile to AutoShootProjectile, the projectile should be deleted when it hits the world limit.
Hope this helps.
08/20/2009 (2:42 am)
Here's some code from my autoshoot behavior:if (!isObject(AutoShootBehavior))
{
%template = new BehaviorTemplate(AutoShootBehavior);
%template.friendlyName = "Auto Shoot";
%template.behaviorType = "AI";
%template.description = "Shoots automatically at a target";
%template.addBehaviorField(target, "The target object to shoot at", object, "", t2dSceneObject);
%template.addBehaviorField(projectile, "The projectile to shoot", object, "", t2dSceneObject);
%template.addBehaviorField(speed, "The projectile speed", float, "10.0");
%template.addBehaviorField(range, "The activity range (objects within this range will be shot", integer, "20");
%template.addBehaviorField(angle, "Objects within this angle will be shot", integer, "45");
%template.addBehaviorField(numShots, "The number of shots fired in a row", integer, "3");
%template.addBehaviorField(shotDelay, "The delay between shots fired in a row", integer, "3000");
}
function AutoShootBehavior::onAddToScene(%this)
{
%this.owner.stopShooting = false;
}
function AutoShootBehavior::shoot(%this)
{
if (!isObject(%this.target) || !%this.target.getVisible() || %this.owner.stopShooting)
return;
%this.owner.shootTimer = %this.schedule(%this.shotDelay, "shoot");
if(%this.range $= 0)
%dist = %this.range;
else
%dist = t2dVectorDistance(%this.owner.getPosition(), %this.target.getPosition());
if(%dist > %this.range)
return;
%origin = %this.owner.getPosition();
%fvec = rotationToVector( %this.owner.getRotation() );
%targetPos = %this.target.getPosition();
%inRange = pointInSight( %origin, %fvec, %targetPos, %this.angle );
if(!%inRange)
return;
%pro = %this.projectile.cloneWithBehaviors();
%pro.position = %this.owner.getPosition();
%pro.scenegraph = %this.owner.getScenegraph();
// moveTo(t2dVector positionTarget, float linearSpeed,[bool autoStop=true],[bool callback=false],[bool snap=true],[float targetMargin=0.1])
%pro.moveTo(%targetPos, %this.speed, false, false, false, 0);
}
function AutoShootProjectile::onWorldLimit(%this, %limitMode, %limit)
{
// Delete the projectile when it hits the world limit
%this.safeDelete();
}If you set the class of the projectile to AutoShootProjectile, the projectile should be deleted when it hits the world limit.
Hope this helps.
Torque Owner Shaderman