I've been trying for a while to get realistic-ish missile trails using the native particle system, but gave up and wrote some code this afternoon which does it nicely.
image deleted
This code is really pitched at a newbie, since it's quite simple. I suppose it's just handy to have knockin about really. It only handles one missile at a time (so you can't unleash terror) which is what I need in my game, but I suppose that could be easily adapted with a 'Missile Age' array...
sync on
sync rate 30
autocam off
color backdrop rgb(0,0,0)
load image "smoke.bmp", 2
` -- convert ambient to point light
set ambient light 0
set point light 0,0,0,0
set light range 0, 10000
` -- make matrix stuff
make matrix 1,5000,5000,20,20
position matrix 1,0,0,0
randomize matrix 1,80
update matrix 1
` -- make player --
make object sphere 1, 10
set object 1,1,1,1,1,1
color object 1,rgb(255,255,255)
global px# as float
global py# as float
global pz# as float
global ay# as float
ay# = 0
px# = 2500
pz# = 2500
py# = 100
` -- make missile --
make object cube 100,5
color object 100,rgb(128,0,0)
hide object 100
global bMissileFlying as boolean : bMissingFlying = 0
global bShooting as boolean : bShooting = 0
` -- missile params
global iMissileSpeed as integer : iMissileSpeed = 8
global iMissileAge as integer : iMissileAge = 0
global iMissileLife as integer : iMissileLife = 200
` -- smoke params
global iSmokeInterval as integer : iSmokeInterval = 0
global iCurrentSmoke as integer : iCurrentSmoke = 0
global iSmokeLife as integer : iSmokeLife = 250
global iNumberSmokes as integer : iNumberSmokes = 150
` -- if aSmokeAge(i) == 0, then it's dead
global dim aSmokeAge(iNumberSmokes) as integer
for i = 1 to iNumberSmokes
aSmokeAge(i) = 0
make object plain 500+i,15,15
color object 500+i, rgb(255,255, 255)
hide object 500+i
texture object 500+i,2
ghost object on 500+i
fade object 500+i, 0
next i
` --------------------------- MAIN LOOP --------------------------- `
do
if leftkey()=1 then ay# = wrapvalue(object angle y(1) - 2)
if rightkey()=1 then ay# = wrapvalue(object angle y(1) + 2)
if upkey()=1:
px# = newxvalue(px#, ay#, 5)
pz# = newzvalue(pz#, ay#, 5)
endif
if spacekey()=1 and bMissileFlying = 0 then bShooting = 1
if bShooting = 1:
` -- set up missile params
iCurrentSmoke = 0
bMissileFlying = 1
bShooting = 0
iMissileAge = 0
` -- align missile to the gun
position object 100, px#, py#, pz#
yrotate object 100,ay#
show object 100
endif
if bMissileFlying = 1:
` -- fly the missile
inc iMissileAge,1
inc iSmokeInterval,1
move object 100,iMissileSpeed
` -- time to create a smoke? --
if iSmokeInterval > int(iMissileLife/iNumberSmokes):
inc iCurrentSmoke, 1
` -- make this smoke become alive
aSmokeAge(iCurrentSmoke) = 1
` -- make it appear
show object 500+iCurrentSmoke
fade object 500+iCurrentSmoke, 100
` -- place it here
position object 500+iCurrentSmoke, object position x(100), object position y(100), object position z(100)
` -- make sure this event only triggers when we want it to
iSmokeInterval = 0
endif
endif
` -- age each active smoke --
for i = 1 to iNumberSmokes
if aSmokeAge(i) > 0:
yrotate object 500+i, camera angle y()-180
inc aSmokeAge(i),1
position object 500+i, object position x(500+i), object position y(500+i)+0.05, object position z(500+i)
a# = aSmokeAge(i)
b# = iSmokeLife
` -- not sure why I have to do this here - can't seem to implicity cast to floats
fade object 500+i, 100-((a#/b#)*100)
` -- kill old smokes --
if aSmokeAge(i) > iSmokeLife:
hide object 500+i
aSmokeAge(i) = 0
endif
endif
next i
` -- time to kill the missile? --
if iMissileAge > iMissileLife:
hide object 100
bMissileFlying = 0
endif
` -- update boring stuff
position object 1, px#,py#,pz#
position light 0, newxvalue(px#,ay#-180,600), py#+400, newzvalue(pz#,ay#-180,600)
yrotate object 1, ay#
set camera to follow px#, py#, pz#, ay#, 50, py#, 5, 0
point camera px#, py#, pz#
sync
loop
If you use this in a game and you feel like crediting me, go for it. If you don't, then it's not like you wouldn't have figured this out for yourself after a while...
Enjoy
-- edited -- removed a text() call in the example
A wise man once said: "I know that I need codes but I dont know the codes"