Dynamically changing particle effects
by Aaron Foley · in Torque Game Builder · 04/20/2005 (12:43 am) · 2 replies
I'm currently trying to learn T2D using the space scroller demo. One of the things i'm trying to accomplish is the ability to speed up and slow down the ship. Now i'm using a particle effect for the thruster of the ship, and am dynamically changing the size of the particle effect to signify how fast or slow the player is going. Now i've figured out how to change the size of the particle effect, but the problem i'm having is that it keeps overlapping the particle effect onto itself. I know its just creating a new effect, and placing it over the old one. So first i've tried to dismount it, but that isn't working the way I hoped. Is there any way to dismount, or remove a particle effect? If so how?
Thanks for your time,
Slyprid
Thanks for your time,
Slyprid
About the author
#2
Also, there's a cleaner way to access objects other than making them global (nice when your projects get real big):
When you attach the thruster, you can add a line that shows who "owns" the thruster (or whatever):
Then your function to change the thruster size might look like this:
Hope that helps
04/20/2005 (5:30 am)
If you call these lines when you want to change the size, you shouldn't have to delete and recreate it:$thruster.selectGraph(sizex_scale); $thruster.setDataKeyValue(0,%length);
Also, there's a cleaner way to access objects other than making them global (nice when your projects get real big):
When you attach the thruster, you can add a line that shows who "owns" the thruster (or whatever):
%MountObj.thruster = %thruster;
Then your function to change the thruster size might look like this:
function PlayerThrust(%thrust)
{
$Player.thruster.selectGraph(sizex_scale);
$Player.thruster.setDataKeyValue(0,%thrust);
}Hope that helps
Torque Owner Aaron Foley
1. First I created a new function called attachPlayerThruster. The reason I did this is to make sure I don't change all of the thruster effects on the ships.
2. Next I changed the %thruster to $thruster. This allows me to manipulate thruster outside of the function
3. I created a side function called playerThrust. This acts as the call point to delete old thruster, than add new one.
4. Added playerThrust calls into keybinds for speed up, and slow down, and also player create.
// Code
function playerThrust()
{
$thruster.safeDelete();
attachPlayerThruster( $player, "-0.12 -0.33", 0,$playerThrust);
}
function attachPlayerThruster(%mountObj, %mountPosition, %angle, %length)
{
$thruster = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
$thruster.loadEffect("~/client/effects/smallThruster.eff");
$thruster.mount( %mountObj, %mountPosition, 0, false );
$thruster.setRotation( %angle );
$thruster.selectGraph(sizex_scale);
$thruster.setDataKeyValue(0,%length);
$thruster.playEffect();
}