Game Development Community

%enemyfire script question

by Patrick Sullivan · in Torque Game Builder · 03/12/2005 (3:36 pm) · 5 replies

Ok I'm going through the tutorial that comes with T2D to get a feel for torquescript as I never used the TGE, and I'm having an odd issue (perhaps it comes up later in the tutorial). I decided to do a test and make it so I could cause the enemy to fire by hitting the g key. This part works. However it doesn't seem to update enemy position when it does the firing, always launching the missile from where the enemy first loaded.

Here's the code in CreateEnemy

%enemy = new fxStaticSprite2D() {scenegraph = t2dSceneGraph; };
%enemy.setSize("14 7");
%enemy.setPosition("39 0");
%enemy.setImageMap(enemyshipImageMap);
%enemy.setLinearVelocityX(-20);
%enemy.setWorldLimit( kill, "-60 -40 60 40" );
%enemy.fireLinkPoint = %enemy.addLinkPoint( "0.45 0.2" );

and here's the code in EnemyFire

%enemyFire = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemyFire.setPosition(%enemy.getLinkPoint(%enemy.fireLinkPoint) );
// %enemyFire.setPosition( %enemy.getPosition() );
%enemyFire.setSize( "3 1.5" );
%enemyFire.setImageMap( enemymissileImageMap );
%enemyFire.setLinearVelocityX( -35 );
%enemyFire.setWorldLimit( kill, "-60 -40 60 40" );

(the fireLinkPoint stuff was testing to see if using a linkpoint would make it work any better, but no real luck there).

About the author

Recent Threads


#1
03/12/2005 (4:12 pm)
If you want a specific enemy to fire you have to know the object id of the enemy you want to fire.

Say you spawn 4 enemys
Enemy Object
1 1624
2 1643
3 1666
4 1673

If I want the first one I spawned to fire I would need to know 1624 is that enemy.

so in your fire code you would need to have something like this:

function enemyFire(%enemy) {
<stuff here>
}

when you bind the key to G if you want a random enemy to fire then you need to make a function to get a random enemy object from a list then have that being used in the g bind.


Note: I believe thats what you need. The problem being that the g key is and can only be bound to one command (or so I believe).
#2
03/12/2005 (4:37 pm)
Ah HA.

Note as of this time there is only one enemy, but if I still need an enemy ID I will look into that, although $player seems to work, or can there only be a single $player object at a time? (i'd assume not since IIRC T2D supports MP).

Hrm time to do more research its starting tos ound like (or just keep doing the tutorial as is and accept it for now =-P)
#3
03/12/2005 (4:49 pm)
In the creation of an enemy you are actually setting an object ID.

%enemy = new fxStaticSprite2D() {scenegraph = t2dSceneGraph; };

Right there, %enemy is the object id for that enemy. Since you use a % its local and once the function has finished it gets deleted (the %enemy var not the object)

If you want to make a list of enemys you might want to have some sort of array like $enemy[%i] = new blahblahblah. This way you can have an enemy fire by instead of object ID by spawn number.
#4
03/12/2005 (5:06 pm)
Hmmm interesting and handy tidbit. And so THAT is what $ vs % means. Maybe I need to sit down and read all the details of torquescript soon hrmmmm.

Thanks :)
#5
03/12/2005 (6:03 pm)
I had a similar issue -- I wanted to loop through all the currently active %enemy(s) and perform some processing on them. I ended up using a Simset. Check out this thread for info (and some code) on simsets. Of course, if you want to perform an action on a specific enemy and not a group (or random) enemy, I don't think simsets would help you.