Particles "bounce" off walls
by WDDG · in Torque Game Builder · 05/09/2006 (9:11 pm) · 15 replies
Is it possible to have a particle effect bounce of the walls? I have a simple game where when you destroy an enemy it is blown to pieces. In my game the wall boundries are very visible in each level.
Is it possible to set worldlimits on particles? Right now the particles look great, but I don't want it to feel like the player is watching some animation, which is the feeling you get once the particles go right through the wall (each level takes place in a box, so i only need worldlimit collisions).
I know the particle system is fast because it's very optimized, but the reference docs make it seem as if there are a few settings I should be able to set to have my particles respect the world limits, however when I try these functions they don't have any effect at all.
Is it possible to set worldlimits on particles? Right now the particles look great, but I don't want it to feel like the player is watching some animation, which is the feeling you get once the particles go right through the wall (each level takes place in a box, so i only need worldlimit collisions).
I know the particle system is fast because it's very optimized, but the reference docs make it seem as if there are a few settings I should be able to set to have my particles respect the world limits, however when I try these functions they don't have any effect at all.
About the author
#2
Can anyone let me know what i'm doing wrong?
05/10/2006 (7:36 pm)
I have _definitely_ tried that, however I don't see the affects of those methods whatsoever.Can anyone let me know what i'm doing wrong?
function initEffect(%source, %effectFile)
{
%pos = %source.getPosition();
%effect = new t2dParticleEffect() { scenegraph = t2dScene; };
%effect.loadEffect(%effectFile);
%effect.setPosition(%pos);
%effect.setEffectLifeMode(KILL, 0.1);
%effect.setLayer(30);
%effect.setEffectCollisionStatus(false);
%effect.setWorldLimit(BOUNCE,$worldBox); //enclose it within box
scaleQuantity(%effect);
return %effect;
}
#3
Something like:
(edit: Change effect var from global to local so there's no confusion)
05/10/2006 (7:49 pm)
I've not implemented particle collisions myself, but don't you still have to specify the collision masks and turn on collisions like other scene objects? Something like:
%effect.setCollisionsActive(true, true); %effect.setCollisionMasks(<whatever bitwise group(s) you're colliding with>);
(edit: Change effect var from global to local so there's no confusion)
#4
Also, from a brief glance at the Reference PDF (Particle Engine.PDF - page 14) it seems that only Clamp, Bounce, Sticky and Kill collision responses are handled.
If your collision polygon isn't set to one of those, it won't work at all
Also, even if it is set to one of those 4 responses, you may need to handle stuff in the onParticleCollision callback, though I'm uncertain about that point
05/10/2006 (8:00 pm)
What (non-particle) objects are you attempting to collide against? Do they have collision polygons assigned? Also, from a brief glance at the Reference PDF (Particle Engine.PDF - page 14) it seems that only Clamp, Bounce, Sticky and Kill collision responses are handled.
If your collision polygon isn't set to one of those, it won't work at all
Also, even if it is set to one of those 4 responses, you may need to handle stuff in the onParticleCollision callback, though I'm uncertain about that point
#5
However I am not able to achieve collisions upon the particles of any sort. I have attempted to define the bitmask and apply particle collisions solely in an attempt see if it would work, but even still nothing occured.
05/10/2006 (8:12 pm)
I actually only wish to have worldlimit collisions. I do not in actuallity wish to use the normal collision system in T2D, but only the bounding box rectangle optimized worldlimit collisions.However I am not able to achieve collisions upon the particles of any sort. I have attempted to define the bitmask and apply particle collisions solely in an attempt see if it would work, but even still nothing occured.
#6
05/10/2006 (8:58 pm)
If I'm not mistaken, world limit collisions for particles do not work. But the normal collision system does. That means you need to create 4 boxes to line the outside of your world, forming your *new* world limits and set collisions to them. Make sense?
#7
05/10/2006 (10:13 pm)
Perfectly, was thinking of that as alternative option. Out of curiousity, what are the chances of world limit collisions being applied to the engine for a future release?
#8
05/10/2006 (11:16 pm)
It's probably not that hard to add, but I doubt it's high on GG's list. particle collisions were low on the list in the first place until a handful of us begged, pleaded and lobbied in these forums and Melv decided to hack it up over a weekend.
#9
Is anyone willing to post a simple example with code.
Here's what I have
05/15/2006 (10:19 pm)
I still havn't had any luck with this. I can't get my particles to collide with anything whatsoever.Is anyone willing to post a simple example with code.
Here's what I have
%pos = %source.getPosition();
%effect = new t2dParticleEffect() { scenegraph = t2dScene; };
%effect.loadEffect(%effectFile);
%effect.setPosition(%pos);
%effect.setEffectLifeMode(KILL, 0.1);
%effect.setLayer(30);
%effect.setEffectCollisionStatus(true);
%effect.setCollisionGroups("31");
%effect.setCollisionResponse( bounce );
#10
It's important to point out (as it states in the reference doco) that getting particles to collide is exactly the same as getting any other object to collide with the additional step of turning-off the effect-collision which promotes the collisions to the particles themselves. Again, note that the effect itself will have a collision-polygon and so will collide (or should do) until you turn off the effect collision status.
- Melv.
05/16/2006 (12:33 am)
Assuming, using the settings above, the particle-effect object itself (not the particles) collide with the world then you simply need to change the call...%effect.setEffectCollisionStatus(true);...to...
%effect.setEffectCollisionStatus(false);
It's important to point out (as it states in the reference doco) that getting particles to collide is exactly the same as getting any other object to collide with the additional step of turning-off the effect-collision which promotes the collisions to the particles themselves. Again, note that the effect itself will have a collision-polygon and so will collide (or should do) until you turn off the effect collision status.
- Melv.
#11
Here's what I have for the particles.
Here's what I have for the object that it should colide against (1 of four walls I made for fake world limits)
Where am I goign wrong?
05/16/2006 (12:06 pm)
I still have no luck with this.... I feel like there's some small thing I'm doing wrong or something. Actually I feel like it just doesn't work. Here's what I have for the particles.
function initEffect(%source, %effectFile)
{
%pos = %source.getPosition();
%effect = new t2dParticleEffect() { scenegraph = t2dScene; };
%effect.loadEffect(%effectFile);
%effect.setPosition(%pos);
%effect.setEffectLifeMode(KILL, 0.1);
%effect.setLayer(30);
%effect.setGraphGroup(30);
%effect.setEffectCollisionStatus(false);
%effect.setCollisionMasks(BIT(31), BIT(31));
%effect.setCollisionResponse( bounce );
scaleQuantity(%effect);
return %effect;
}Here's what I have for the object that it should colide against (1 of four walls I made for fake world limits)
//left border
%border = new t2dStaticSprite() { sceneGraph = t2dScene; };
%border.setImageMap(pixel);
%border.setBlending(false);
%border.setSize(0.1,66);
%border.setPosition($worldLeftEdge,0);
%border.setLayer(31);
%border.setGraphGroup(31);
%border.setCollisionActive(true,true);
%border.setCollisionMasks(BIT(30), BIT(30));Where am I goign wrong?
#12
05/17/2006 (10:02 am)
Anyone? Today's my birthday! This would be an awesome gift.
#14
I have it set to,
%effect.setCollisionResponse( bounce );
As a test i set it to,
%effect.setCollisionResponse(clamp);
and they did same thing, only the angle of the objects was flattened, so it seems they're having slightly different effects on the object.
Thanks for everyone's help so far. Almost there!
05/17/2006 (8:37 pm)
So that definitely did _something_, however now I'm having a weird bug where the particles are essentially clamping to the object on collision.I have it set to,
%effect.setCollisionResponse( bounce );
As a test i set it to,
%effect.setCollisionResponse(clamp);
and they did same thing, only the angle of the objects was flattened, so it seems they're having slightly different effects on the object.
Thanks for everyone's help so far. Almost there!
#15
- Melv.
05/18/2006 (7:20 am)
The bounce uses the restitution parameter to control how bouncy the bounce is. Try using "setRestitution(1)" although it should be 1 by default so I'm not convinced that's it. This a direct function that would alternatively be set by the collision material.- Melv.
Torque Owner Jason Cahill
Default Studio Name