Shooting
by Bruno · in Torque Game Builder · 09/22/2005 (3:34 pm) · 5 replies
Hi,
I'm tryng to have enemys shooting several shots at the player, but i'm being unsucessefull.
What i do is a make a Create_Enemy1 function, that has a schedule of 2000, so she is allways being generated by
that amount of time.
Inside Create_Enemy1 i do this : "%enemy.schedule(200,"Enemy_Fire");" , so that each 200 time units, that
function is called and a new shot generated.
However, this is not working quite well., no shots are ever displayed.
Can anyone enlight me on what i'm doing wrong ?
I have a feeling the problem is in Enemy_Fire, in the enemyFire.setPosition, he may not know what's the
value of %enemy.getPosition() , but i see no other way to do this.
Thanks for any help,
Bruno
I'm tryng to have enemys shooting several shots at the player, but i'm being unsucessefull.
What i do is a make a Create_Enemy1 function, that has a schedule of 2000, so she is allways being generated by
that amount of time.
Inside Create_Enemy1 i do this : "%enemy.schedule(200,"Enemy_Fire");" , so that each 200 time units, that
function is called and a new shot generated.
However, this is not working quite well., no shots are ever displayed.
Can anyone enlight me on what i'm doing wrong ?
I have a feeling the problem is in Enemy_Fire, in the enemyFire.setPosition, he may not know what's the
value of %enemy.getPosition() , but i see no other way to do this.
function Enemy_Fire()
{
// Load enemy fire thing
%enemyFire = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemyFire.setPosition( %enemy.getPosition() );
%enemyFire.setSize( "3 1.5" );
%enemyFire.setImageMap( enemymissileImageMap );
%enemyFire.setLinearVelocityX( -50 );
%enemyFire.setWorldLimit( kill, "-60 -40 60 40" );
// Set up collision info
%enemyFire.setGroup( 2 );
%enemyFire.setLayer( 2 );
%enemyFire.setCollisionActive( true, true );
%enemyFire.setCollisionMaterial( standardMaterial );
%enemyFire.setCollisionScale("0.9 0.5");
%enemyFire.setCollisionMasks( BIT(1), BIT(1) );
%enemyFire.setCollisionCallback( true );
}
function Create_Enemy1()
{
%enemy = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemy.setSize( "14 14");
%enemy.setPosition("40" SPC (-30 + (getRandom() * 60)));
%enemy.setImageMap( enemyship1ImageMap );
%enemy.setLinearVelocityX(-30);
%enemy.setWorldLimit( kill, "-60 -40 60 40" );
%enemy.setAutoRotation(60);
// Set enemy collision info
%enemy.setGroup( 2 );
%enemy.setLayer( 2 );
%enemy.setCollisionActive( true, true );
%enemy.setCollisionMaterial( standardMaterial );
%enemy.setCollisionPolyCustom( 5, "-0.9 0 0 -0.6 1 -0.3 1 0.3 0 0.5" );
%enemy.setCollisionMasks ( BIT(1), BIT(1) );
%enemy.setCollisionCallback( true );
%enemy.schedule(200,"Enemy_Fire");
schedule(1200,0,"Create_Enemy1");
}Thanks for any help,
Bruno
About the author
#2
09/22/2005 (3:46 pm)
Thanks Adam, i tought the problem would be something like that, but unfortenly it's still not working :(
#4
At the bottom of it if you want continuous 200ms firing. Otherwise each new enemy fires once and stops. (schedules are one-shot, not repeating.)
Oh and to explain what was happening originally for future reference, if you call schedule on an object (%object.schedule(...)) then you are implying that the function you're calling at the schedule time is a member function of the object. Your Enemy_Fire function is not a member of the %enemy object so it never finds it to execute it.
When calling non-member functions you use the syntax "schedule(delay, referenceObject (or zero), function, arg1, arg2, ... argN);"
09/22/2005 (7:15 pm)
Your Enemy_Fire function will also need a:schedule(200, 0, "Enemy_fire", %enemy);
At the bottom of it if you want continuous 200ms firing. Otherwise each new enemy fires once and stops. (schedules are one-shot, not repeating.)
Oh and to explain what was happening originally for future reference, if you call schedule on an object (%object.schedule(...)) then you are implying that the function you're calling at the schedule time is a member function of the object. Your Enemy_Fire function is not a member of the %enemy object so it never finds it to execute it.
When calling non-member functions you use the syntax "schedule(delay, referenceObject (or zero), function, arg1, arg2, ... argN);"
#5
09/23/2005 (5:38 am)
Thanks guys, got it working nicely ;)
Torque Owner Adam Larson
Then change your enemy fire function to this:
function Enemy_Fire(%enemy) { ... }