Here's the working code if anyone wants a nosey at it:
function control_bullets()
obj as integer
c as integer
coll as integer
xpos as float
ypos as float
zpos as float
newx as float
newy as float
newz as float
if bullet_fire=0
if mc and 1
array insert at bottom bullets()
obj=WLSG_FIND_OBJECT()
bullets().obj=obj
bullets().spd=3
bullets().grav=0.5
bullets().life=0
make object sphere obj,5
position object obj,object position x(pobj),object position y(pobj),object position z(pobj)
color object obj,0xffff00
set object specular obj,0xffffff
set object specular power obj,5
rotate object obj,-campitch-30,object angle y(pobj),object angle z(pobj)
bullet_fire=20
endif
else
if bullet_fire>0
dec bullet_fire
endif
endif
` process bullet movement first
` traversing backwards through the bullet list because when deleting array elements
` everything gets shuffled backwards to fill the gap
c=array count( bullets() )
while c >= 0
obj=bullets(c).obj
xpos=object position x(obj)
ypos=object position y(obj)
zpos=object position z(obj)
`xrotate object obj,object angle x(obj)+bullets(c).grav
pitch object down obj,bullets(c).grav
move object obj,bullets(c).spd
newx=object position x(obj)
newy=object position y(obj)
newz=object position z(obj)
inc bullets(c).life
coll=SC_SphereCastGroup(1,xpos,ypos,zpos,newx,newy,newz,2,0)
` collided or the bullet has been active for way too long
if coll or bullets(c).life>250
`SC_RemoveObject obj
delete object obj
array delete element bullets(),c
endif
dec c
endwhile
endfunction
It's going to be part of a complete open source game I'm working on.
Warning! May contain Nuts!