Game Development Community

(Solved) Enemy targeting

by Randy Sewell · in Torque Game Builder · 08/18/2012 (6:19 am) · 1 replies

Hi, I have spent the past few days reading through documentation trying to figure this out. I found out a few things about t2dSceneObject that helped me fix one part of my problem, but the actual targeting is still an issue.

function t2dSceneObject::createFireball(%this)
{
   if(!%this.isDead)
   {
      %fireball = new t2dAnimatedSprite()
      {
         scenegraph = %this.scenegraph;
         class = fireball;
      };

      %fireball.fire();
      %this.schedule(2000, "createfireball");
   }
}

function t2dSceneObject::fire(%this)
{
   %this.playAnimation(EmberAnimation);
   %this.setSize(25, 25);
   %this.setLayer(11);
   %this.setCollisionActive( true, true );
   %this.setCollisionPhysics(false, false);
   %this.setCollisionCallback(true);
   
   %psionPosition = $psion.getPosition();
   %this.setPosition(%psionposition);
   
   %playerPosition = $Player.getPosition();    
   %emberAngle = t2dAngletoPoint(%PsionPosition, %playerPosition);          
       
   %this.setLinearVelocityPolar(%emberAngle, 200);    
   
   $backgroundMusic = alxPlay(fireAudio);      
}

Essentially, I have the enemy firing at my player exactly as I need him. The problem is, that since I have used the $psion, I can't have more than one of my enemies on the field because the targeting is global.

Anyone know what I need to do to get my targeting system to look for the specific enemy that is firing instead of all enemies?

#1
08/18/2012 (6:53 am)
Nevermind, solved by partially combining functions.

And I managed to have my psion fire himself at me for awhile there, that was fun. :)

function t2dSceneObject::createFireball(%this)
{
   if(!%this.isDead)
   {
      %this.fire();
      %this.schedule(2000, "createfireball");
   }
}

function t2dSceneObject::fire(%this)
{
   
   %fireball = new t2dAnimatedSprite()
      {
         scenegraph = %this.scenegraph;
         class = fireball;
      };
     
   %fireball.playAnimation(EmberAnimation);
   %fireball.setSize(25, 25);
   %fireball.setLayer(11);
   %fireball.setCollisionActive( true, true );
   %fireball.setCollisionPhysics(false, false);
   %fireball.setCollisionCallback(true);
   
   %psionPosition = %this.getPosition();
   %fireball.setPosition(%psionposition);
   
   %playerPosition = $Player.getPosition();    
   %emberAngle = t2dAngletoPoint(%PsionPosition, %playerPosition);          
       
   %fireball.setLinearVelocityPolar(%emberAngle, 200);    
   
   $backgroundMusic = alxPlay(fireAudio);      
}

If anyone has any advice on how to clean this up or do it better, I am all ears. :)