How to use pickRadius () ?
by Elliot C. · in Torque Game Builder · 11/01/2009 (1:24 pm) · 8 replies
Hi there,
First off, I'm sorry if the solution to my problem is a very simple thing. I'm still very inexperienced with TGB. Just to clarify things up, I am using TGB for a project at school.
I am trying to use an explosion (particle effect), made by a missile. Anything within the explosion is supposed to get damaged. I have learned about pickRadius () , but I have no idea how to use it. I have looked at the documentation to it, and tried to put it into my project, but it continues to tell me that pickRadius is an unknown command.
This is my attempt at creating the code myself:
function specialAttackp1Explode ()
{
$p1ShootReady = true;
player1Special.setLinearVelocityY(0);
player1Special.setLinearVelocityX(0);
$missilespecialexp = missileSpecialExplosion.cloneWithBehaviors ();
$missilespecialexp.Position = player1Special.Position;
player1Special.Position = "400 400";
schedule (1500, 0, "p1MissileAttackCleanup");
p1SpecialAttackRadius ();
}
function p1SpecialAttackRadius ()
{
player1Special.pickRadius ($missilespecialexp.getPositionX(), $missilespecialexp.getPositionY(), 20);
}
There are probably a million and one things that are wrong with the pickRadius code. The thing is, I can't seem to find what is wrong with it. Any suggestions as to what I am doing wrong?
For further information, "player1Special" is the missile. Also, "specialAttackp1Explode" is called by lifting the "f" key (the missile shoots when f is pressed down, and explodes when f is released).
First off, I'm sorry if the solution to my problem is a very simple thing. I'm still very inexperienced with TGB. Just to clarify things up, I am using TGB for a project at school.
I am trying to use an explosion (particle effect), made by a missile. Anything within the explosion is supposed to get damaged. I have learned about pickRadius () , but I have no idea how to use it. I have looked at the documentation to it, and tried to put it into my project, but it continues to tell me that pickRadius is an unknown command.
This is my attempt at creating the code myself:
function specialAttackp1Explode ()
{
$p1ShootReady = true;
player1Special.setLinearVelocityY(0);
player1Special.setLinearVelocityX(0);
$missilespecialexp = missileSpecialExplosion.cloneWithBehaviors ();
$missilespecialexp.Position = player1Special.Position;
player1Special.Position = "400 400";
schedule (1500, 0, "p1MissileAttackCleanup");
p1SpecialAttackRadius ();
}
function p1SpecialAttackRadius ()
{
player1Special.pickRadius ($missilespecialexp.getPositionX(), $missilespecialexp.getPositionY(), 20);
}
There are probably a million and one things that are wrong with the pickRadius code. The thing is, I can't seem to find what is wrong with it. Any suggestions as to what I am doing wrong?
For further information, "player1Special" is the missile. Also, "specialAttackp1Explode" is called by lifting the "f" key (the missile shoots when f is pressed down, and explodes when f is released).
About the author
#2
Thanks for the reply,
Should it look something more like this?:
function p1SpecialAttackRadius ()
{
%tSceneGraph = sceneWindow2D.getSceneGraph();
%tSceneGraph.pickRadius ($missilespecialexp.getPositionX(), $missilespecialexp.getPositionY(), 20);
}
If so, how would I get it to damage opponents? (I'm guessing that more variables go after "pickRadius" but I am clueless to what is supposed to go after). If not, what mistakes have I made, or have I completely messed it up yet again?
11/01/2009 (10:15 pm)
Hi,Thanks for the reply,
Should it look something more like this?:
function p1SpecialAttackRadius ()
{
%tSceneGraph = sceneWindow2D.getSceneGraph();
%tSceneGraph.pickRadius ($missilespecialexp.getPositionX(), $missilespecialexp.getPositionY(), 20);
}
If so, how would I get it to damage opponents? (I'm guessing that more variables go after "pickRadius" but I am clueless to what is supposed to go after). If not, what mistakes have I made, or have I completely messed it up yet again?
#3
Typically, I'll add dynamic variables to the objects as they are created. If you assume that your newly created sprite was called "%enemyShip", I'd immediately add the following line of code (which you can also add manually in TGB).
All other objects would hav ethe "damagable" set to "false".
Then, as you are iterating through the list of returned items, check the flag. If it is "damagable", then apply the damage to it.
11/01/2009 (11:17 pm)
There are a thousand ways to do this, so it's hard to just say "here's how you do it."Typically, I'll add dynamic variables to the objects as they are created. If you assume that your newly created sprite was called "%enemyShip", I'd immediately add the following line of code (which you can also add manually in TGB).
%enemyShip.damagable = true;
All other objects would hav ethe "damagable" set to "false".
Then, as you are iterating through the list of returned items, check the flag. If it is "damagable", then apply the damage to it.
#4
Sorry about the late reply,
I couldn't seem to figure out how to do it correctly, so after extensive searching, I managed to scrape up this:
%tSceneGraph = sceneWindow2D.getSceneGraph();
%explosionRadius = %tSceneGraph.pickRadius ($missilespecialexp.getPosition(), 7);
%explosionHit = getWordCount(%explosionRadius);
for (%i = 0; %i < %explosionHit; %i++)
{
if ($p1specialenabled)
{
$p1specialenabled = false;
p2Character.Player2Life -= 30;
}
}
It seems to work at times, and not at other times. The first thing is that the radius doesn't seem to function correctly. Is the radius supposed to be one number, like what I did (7)? Or something more like this: ("10 10")?
Also, the documentation states that:
You can change the layers that the radius applies to with [%layerMask = MASK_ALL]
but I have no idea how to use it.
11/11/2009 (9:41 pm)
Hi,Sorry about the late reply,
I couldn't seem to figure out how to do it correctly, so after extensive searching, I managed to scrape up this:
%tSceneGraph = sceneWindow2D.getSceneGraph();
%explosionRadius = %tSceneGraph.pickRadius ($missilespecialexp.getPosition(), 7);
%explosionHit = getWordCount(%explosionRadius);
for (%i = 0; %i < %explosionHit; %i++)
{
if ($p1specialenabled)
{
$p1specialenabled = false;
p2Character.Player2Life -= 30;
}
}
It seems to work at times, and not at other times. The first thing is that the radius doesn't seem to function correctly. Is the radius supposed to be one number, like what I did (7)? Or something more like this: ("10 10")?
Also, the documentation states that:
You can change the layers that the radius applies to with [%layerMask = MASK_ALL]
but I have no idea how to use it.
#5
There are many other ways to do this, too. For example, you could put the player on its own group and use the groupMask. Then if anything was returned from the "pickRadius", it would have to be your player.
11/11/2009 (9:54 pm)
In your code, as long as ANY object is in your radius, you are modifying the p2Character. Inside your for-loop, you could do something like:%obj = getWord( %explosionRadius, %i );
if( %obj == p2Character.getId() )
{
p2Character.Player2Life -= 30;
}There are many other ways to do this, too. For example, you could put the player on its own group and use the groupMask. Then if anything was returned from the "pickRadius", it would have to be your player.
#7
}
for (%i = 0; %i < %explosionHit; %i++)
{
%obj = getWord( %explosionRadius, %i );
if ($p1specialenabled && %obj == p2Character.getId())
{
$p1specialenabled = false;
p2Character.Player2Life -= 30;
}
if ($p1specialenabled && %obj == p3Character.getId())
{
$p1specialenabled = false;
p3Character.Player3Life -= 30;
}
}
}
It works when each character is hit seperately, but when both characters are in the same radius, only Player2 gets damaged. Any way to get them to both be damaged?
11/11/2009 (11:36 pm)
Sorry to bug you again, but I have a small problem again;}
for (%i = 0; %i < %explosionHit; %i++)
{
%obj = getWord( %explosionRadius, %i );
if ($p1specialenabled && %obj == p2Character.getId())
{
$p1specialenabled = false;
p2Character.Player2Life -= 30;
}
if ($p1specialenabled && %obj == p3Character.getId())
{
$p1specialenabled = false;
p3Character.Player3Life -= 30;
}
}
}
It works when each character is hit seperately, but when both characters are in the same radius, only Player2 gets damaged. Any way to get them to both be damaged?
#8
1) Both objects are in the pick radius.
2) Object p2Character is found.
3) $p1specialenabled is set to false.
4) Object p3Character is found, but $p1specialenabled is not true anymore.
It's easy to fix, though! Before the for-loop, set a variable (%disablep1special) to false. In your if-checks, set that variable to true. After the for-loop, if %disablep1special is true, then set $p1specialenabled to false.
11/12/2009 (12:54 am)
There's a logic error.1) Both objects are in the pick radius.
2) Object p2Character is found.
3) $p1specialenabled is set to false.
4) Object p3Character is found, but $p1specialenabled is not true anymore.
It's easy to fix, though! Before the for-loop, set a variable (%disablep1special) to false. In your if-checks, set that variable to true. After the for-loop, if %disablep1special is true, then set $p1specialenabled to false.
%disableP1Special = false;
for( %i = 0; %i < %explosionHit; %i++ )
{
%obj = getWord( ... );
if( $p1specialenabled && %obj == p2Character.getId() )
{
%disableP1Special = true;
p2Character.Player2Life -= 30;
}
// Same for p3Character...
}
if( %disableP1Special )
{
$p1specialenabled = false;
}
Associate William Lee Sims
Machine Code Games
tdn.garagegames.com/wiki/TGB/Reference:_t2dSceneGraph
You'll see that pickRadius returns a list of space separated objects. You'll have to use "getWord()" to go through the list.