Particle Bounce, Need some Help
Blitz3D Forums/Blitz3D Programming/Particle Bounce, Need some Help
| ||
Ok, I wrote a really simple particle engine, and I ran into a little snag with making the particles rebound. I tried using the generic bouncing code from the code archives, but I'm not quite sure how to blend it with my code...Here's the particle code I wrote. If anyone can tell me how to add rebound to it I'll be very grateful. (Note sure how to do a code box...sorry) Type Particle Field Entity,XSpeed#,YSpeed#,ZSpeed#,Alpha#,Lifespan End Type Function CreateParticle.Particle(X,Y,Z,Sprite,Lifespan=100,R=255,G=255,B=255) p.Particle = New Particle p\Entity = Sprite p\XSpeed = 0 p\YSpeed = 2 p\ZSpeed = 1 p\Alpha = 1 p\Lifespan = Lifespan EntityType(p\Entity,CT_PARTICLE) EntityColor(p\Entity,R,G,B) PositionEntity(p\Entity,X,Y,Z) RotateEntity(p\Entity,0,Rand(360),0) Return p End Function Function UpdateParticles() For p.Particle = Each Particle MoveEntity(p\Entity,p\XSpeed,p\YSpeed,p\ZSpeed) p\YSpeed = p\YSpeed - 0.1 If p\Lifespan > 0 Then p\Lifespan = p\Lifespan - 1 Else If p\Alpha > 0 Then p\Alpha = p\Alpha - 0.1 EntityAlpha(p\Entity,p\Alpha) Else FreeEntity p\Entity Delete p EndIf EndIf Next End Function |
| ||
I don't need anything too fancy, just basic bounce for stuff like spent brass and debris...that sort of thing. No need to be mathematically correct or anything, just needs to look good. |
| ||
Well, for a simple bounce off the ground, just invert the y speed and decrease it all the time :) |
| ||
That would be great, except I don't know how to find out when the particle hits something that should invert it (like the floor). Y of 0 is not the universal floor in my project... |
| ||
With a particle system it is probably best not to use collisions as that will slow things down. You could add a floor parameter to your particle system so if a particle goes below a certain value then reverse the Y velocity and multiply it by somthing smaller than 1 (say 0.95) to make it lose energy. |