Flint Particle System Forum - Change particles velocity wihtout change its direction Thu, 02 Jun 2016 18:41:08 +0100 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Change particles velocity wihtout change its direction http://flintparticles.org/forum/comments.php?DiscussionID=577&Focus=1972#Comment_1972 http://flintparticles.org/forum/comments.php?DiscussionID=577&Focus=1972#Comment_1972 Tue, 06 Nov 2012 17:10:28 +0000 dfdiaza I have some particles moving inside a BoundingBox, but I need to have a Slider control, so I can change the particles velocity without change their directions.
I don't have idea how to achieve it. Can you help me please?

Regards,
Diego

Here is the current code with the particles inside a BoundingBox

import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.RadialDot;
import org.flintparticles.common.initializers.*;
import org.flintparticles.twoD.actions.*;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.initializers.*;
import org.flintparticles.twoD.renderers.*;
import org.flintparticles.twoD.zones.*;

var emitter:Emitter2D = new Emitter2D();
emitter.counter = new Blast( 10 );
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
renderer.addEmitter( emitter );
addChild( renderer );






var moleculeGroup:InitializerGroup = new InitializerGroup();
moleculeGroup.addInitializer(new ImageClass(Asteroide) );

var bounds:Rectangle = new Asteroide().getBounds(this);
moleculeGroup.addInitializer(
new CollisionRadiusInit(
Math.max(bounds.width,
bounds.height)/2)
);


moleculeGroup.addInitializer(new Position( new RectangleZone( 150,150,300,300) ));
moleculeGroup.addInitializer(new Velocity( new PointZone( new Point( 100,100 ))));


emitter.addInitializer(moleculeGroup);
emitter.addAction( new Move() );
emitter.addAction(new Collide(1));
emitter.addAction(new BoundingBox(150,150,300,300))



emitter.start();

//TODO:
function changeSpeed()
{
how can I change the speed for all the particles from my emitter?
} ]]>
Change particles velocity wihtout change its direction http://flintparticles.org/forum/comments.php?DiscussionID=577&Focus=1973#Comment_1973 http://flintparticles.org/forum/comments.php?DiscussionID=577&Focus=1973#Comment_1973 Tue, 06 Nov 2012 21:08:45 +0000 dfdiaza
for(var i=0;i<emitter.particles.length;i++)
{
var p:Particle2D = Particle2D( emitter.particles[i] );
var loc:Point = new Point(velocity,velocity) // A point zone with my desired velocity.
if( p.rotation == 0 )
{
p.velX = loc.x;
p.velY = loc.y;
}
else
{
var sin:Number = Math.sin( p.rotation );
var cos:Number = Math.cos( p.rotation );
p.velX = cos * loc.x - sin * loc.y;
p.velY = cos * loc.y + sin * loc.x;
}
} ]]>