Particles
Blitz3D Forums/Blitz3D Programming/Particles
| ||
| Hi, I was wandering if anyone could help me on how to make particle fx, at present i just want to make a very simple particle system, but need to know how to make the particles, I'm trying to make a cube which has spheres coming out of it an rising inot the air, can anyone help me please. Please reply. |
| ||
| Double post ? I think not :) |
| ||
| Well, first of all, a particle is a low poly mesh, or a sprite, or a quad. Each particle has it's own X,Y,Z co-ords, it's own speed and life time etc etc. So your best to set up a type collection to hold all this data in. Type particle Field x#,y#,z ; the x ,y ,z co-ords of the particle Field life_time ; how long the particle will "live" for Field timer; keeps track of how long the entity has lived Field speed# ; the speed the particle will travel at End Type Ok, so now you have set up a type to store the particles, you new some code to handle them Run the code below. Press the up arrow to generate particles :) Please note that this is a verrrry basic example :)
Graphics3d 800,600
setbuffer backbuffer()
global cam=createcamera()
positionentity cam,0,1,-10
global light=createlight()
global cube_emittor=createcube()
global main_particle=createsphere(3)
Type particle
Field entity
Field x#,y#,z ; the x ,y ,z co-ords of the particle
Field life_time ; how long the particle will "live" for
Field timer; keeps track of how long the entity has lived
Field speed# ; the speed the particle will travel at
End Type
while not keyhit(1)
If keydown(200) then; if the up arrow is pressed then
; \/ pass across the cube_emittors X,Y,Z co-ords, a speed value, and a timer value, to create a new particle.
create_particle(entityx(cube_emittor),entityy(cube_emittor),entityz(cube_emittor),rnd(0.1,0.3),rnd(10,300))
End If
update_particles(); calling this, updates the particle, by moving it, and checks to see if it's life_time has run out.
UpdateWorld
RenderWorld
Flip
Wend
End
Function create_particle(x#,y#,z#,speed#,life_time)
p.particle=new particle
p\entity=copyentity(main_particle); copy the main_particle entity to p\entity, so the type object can use a copy of it
EntityColor p\entity,Rnd(100,250),Rnd(100,250),Rnd(100,250); give each particle a random colour
entityalpha p\entity,0.4 ; set the particle to be see thru
p\x=rnd(x-1,x+1); random x position, based on cube emittors position
p\y=y; y position, based on cube emittors position
p\z=rnd(z-1,z+1); random z position, based on cube emittors position
PositionEntity p\entity,p\x,p\y,p\z; position the entity
p\speed=speed; set speed to the speed passed across to the function
p\life_time=life_time; set life_time to the speed passed across to the function
p\timer=millisecs(); set the timer to the current value of millisecs
End Function
Function update_particles()
for p.particle=each particle
moveentity p\entity,0,p\speed,0; move the entity along the Y axis, using the speed variable
if millisecs()>p\life_time+p\timer then; check to see if the objects life_time, has ran out
freeentity p\entity; if so, then free the entity
delete p.particle; delete the type object
end if
next
End function
|
| ||
| Thanks you, i should get a good start with that. |
| ||
| Ok, i have got somewhere, I have made smoke and mist, :), but know i just need to know something else, how do you make flares, i know you need to load a sprite with a sort of flare but how do you get the effect of it glowing like in the druid demo, please help if you can. :) i hope to make a simple demo or project soon. |
| ||
Well, you can set each particles blend mode to mode 3.EntityBlend p\entity,3 That's should do the trick. When two or more particles overlap, they will have a sort of glow effect round them :) |
| ||
| Ok, thanks for that, it was sort of what i ment but i will help me, what i realy meant was a single sprite and how to get to it look like i does really glow, like the flare in Druit that are one in the staff which the player hold and when casting the spell the flares that appear above the stones. |
| ||
| Ive not seen what you're referring to, but do you mean actually light the surroundings? These sort of effects can be very technical and, especially with the dynamic nature of flickering flames, quite difficult. Ehhh I'd love to be able to help but it's way beyond me, save for adding a hardware light (CreateLight()) at the position of the emitter and maybe varying it's brightness slightly but frequently. |
| ||
| You could have a solid circle texture on one, and a glow texture on the other. The glow texture will be using EntityBlend mode 3. Try that :) |
| ||
| Sorry i dont quite understand what you mean. |
| ||
| Never mind that in fact :) Just one sprite should be enough. But you probably need to overlay over particles on it, so the blend effect makes it glow. Check out the file below. Take a look at the image used for the sprite. http://www.rosscrooks.pwp.blueyonder.co.uk/particle_glow.zip :) |
| ||
| you can get the flare effect if you do a linepick from the camera to each particle to check if a particle is visible at all, and if it's visible, then unhide a second sprite that is located at the same position, has blendmode 3 and a nice flare gfx and most important uses ENtityOrder in a way to draw it in front of everything. But linepicks are not very fast, so it could hit the performence if you have hundreds of particles. |
| ||
| ok, thanks Ross c. and i would like to thank everyone else here who helped me aswell. |