Game Development Community

Rotating Particle Emitters

by Casey Young · in Torque Game Builder · 10/03/2005 (4:56 pm) · 6 replies

Ok, this problem was buggin me out for a while, and I searched and searched for the answer throughout this board. Well, I picked up bits and pieces here and there, and I decided I would share what I found.

My problem: I wanted a particle effect to follow a ship that rotates around and around (like the little ship in asteroids). This would be the effect for the thrusters firing. I couldn't get it to rotate at all when the ship rotated.

First I would attatch the thruster to the ship with this function:
//-----------------------------------------------------------------------------
// Create and Attach Thruster.
//-----------------------------------------------------------------------------
function attachThruster(%mountObj, %mountPosition, %angle)
{
	// Create Player Thruster.	
	%thruster = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
	%thruster.loadEffect("~/client/effects/playershipthrust.eff");
	%thruster.setLayer( %mountObj.getLayer()+1 );
	%thruster.mount( %mountObj, %mountPosition, 0, false );
	%thruster.setRotation( %angle );
	%mountObj.thruster = %thruster;
}

I created a variable to tell when the ship is rotating:
$playerIsRotating = false;

In my code to do the handling to turn left and right, I did the following (This is just for Rotating Right, so you would just need to add schedule in the Left to make it work as well):

function playerRotateRight()
{
	// Lets Tell the program that the player is thrusting
	$playerIsRotating = true;
	$player.setAngularVelocity( 140 );
	schedule( 33, 0, "playerRotating");
}

function playerRotateRightStop()
{
	// Lets Tell the program that the player has stopped thrusting
	$playerIsRotating = false;
	$player.setAngularVelocity( 0 );
}

function playerRotating()
{
	$player.thruster.selectGraph("emissionangle_base");
        // add 180 cause at 0, the particles go up, and my ship's back is on the bottom, ^_^
	$player.thruster.setDataKeyValue( 0, $player.getRotation()+180 );
	if( $playerIsRotating == true )
		schedule( 33, 0, "playerRotating");
}

This works like a charm. The particles looks like it comes out the back of my ship! Hope this helps.

--UberMonkey

About the author

Recent Threads


#1
10/04/2005 (12:00 am)
From the Reference doc:
Quote:
setAttachPositionToEmitter()
Set Attach-Position-To-Emitter Flag.
-
In "Attach Position to Emitter" mode, the particles are attached to the emitters position. As the emitter moves, so do the particles.

setAttachRotationToEmitter()
Set Attach-Rotation-To-Emitter Flag.
-
In "Attach Rotation to Emitter" mode, the particles are attached to the emitters rotation. As the emitter rotates, the particles rotate around the emitter using its location as a pivot-point.
NOTE:- This does not affect particle orientation. This can only be used when "Attach Position to Emitter" mode is active.
Would that do the trick?
#2
10/04/2005 (12:30 am)
Casey,

Philip points you to the correct functions. Note that you can go into the particle-editor and select these options there so that your particle effects use them by default.

- Melv.
#3
10/04/2005 (5:20 pm)
Well, in the particle editor, I do have those 2 settings checked. But here is my problem. It is alway pointing the way that it is in the particle editor. I want it to point in the opposite direction the ship is going. I attacted the thruster to the $player, but when I rotate $player, the thruster animation still points the same way... it doesn't rotate with the sprite. Am I missing something here? (I can post my player code if requested).

--UberMonkey
#4
10/05/2005 (12:34 am)
Well...

First, I'd make sure that particle effect does rotate in the particle-editor. Then, assuming it does, when you mount it to the player, make sure that the "trackRotation?" parameter is true. If you've done both of these then the particle-effect will rotate.

Just to be clear; one thing that I get a hint of in your post is that you want the particle-effect to somehow know which way to emit in relation to the player. Obviously it doesn't know this. If you want to use the mount auto-rotation tracking then you need to have a common reference direction. If your ship at rotation zero faces left and you want the thruster emission to emit right at rotation zero then you need to design your particle effect so emission is in that direction at that angle so that when you attach the effect, both the player and the effect are coordinated and the rotation tracking will take it from there. I may be sensing this incorrect but I thought I'd clarify anyway. :)

You can, of course, also turn-off the "trackRotation?" parameter and rotate it manually yourself but there's no need to do this unless you've got some specific effect you're looking for.

Hope this helps,

- Melv.
#5
10/05/2005 (12:03 pm)
Hey thanks Melv. I guess I should of actually taken a look at the mount() function a littel closer. I didn't know about the "trackRotation" flag. The thrusters now work like a charm without all that extra work. For a while there, I thought I wasn't doing something right within the Particle Editor. And yea, what you picked up was right, I wanted it to follow the tail end of my ship as it flew across the screen, and rotate with the ship. Well, now at least I know how to do it manually and automatically. ^_^

--UberMonkey
#6
10/05/2005 (12:24 pm)
Good stuff, glad it's working for you. :)

- Melv.