For some reason when I shoot my weapon and I change between my weapons while im shooting the projectiles stop spawning. Here's the code for my weapon selection
if keystate(2)
currweap = 1
else
if keystate(3)
currweap = 2
endif
endif
if mouseclick()
SHOOT(weap(currweap).radius, weap(currweap).density, weap(currweap).friction, weap(currweap).restitution, weap(currweap).force, weap(currweap).freq, weap(currweap).doc)
endif And here's the code that is the shoot function
FUNCTION SHOOT(radius, density, friction#, restitution#, force#, freq, doc)
if bull(f).active = 0
if char.shooting = 0
char.shooting = 1
bull(f).active = 1
bull(f).shapeID = B2CREATECIRCLESHAPE( 0, 0 ,radius )
bull(f).bodyID = B2CREATEBODY( world, B2BODYTYPE_DYNAMIC(), B2GETBODYPOSITIONX( weap.bodyID ), B2GETBODYPOSITIONY( weap.bodyID ), B2GETBODYANGLE(weap.bodyID), 0, 1 )
bull(f).fixtureID = B2CREATEFIXTURE( bull(f).bodyID, bull(f).shapeID, density, friction#, restitution# )
B2SETBODYISBULLET bull(f).bodyID, 1
B2APPLYBODYLINEARIMPULSE bull(f).bodyID,(cos(B2GETBODYANGLE(weap.bodyID)-90)*force#)* multi,(sin(B2GETBODYANGLE(weap.bodyID)-90)*force#)* multi,B2GETBODYPOSITIONX( weap.bodyID ), B2GETBODYPOSITIONY( weap.bodyID )
if f = 30 then f = 0
ENDIF
ENDIF
IF char.shooting > 0
inc char.shooting,1
if char.shooting = freq
char.shooting = 0
f = f + 1
ENDIF
ENDIF
for i = 0 to 30
if bull(i).active = 1
B2FINDBODYCONTACTS bull(i).bodyID
if doc = 1
if B2GETCONTACT()
fixturea = B2GETCONTACTFIXTUREA()
fixtureb = B2GETCONTACTFIXTUREB()
bodya = B2GETFIXTUREBODY(fixturea)
bodyb = B2GETFIXTUREBODY(fixtureb)
if bodya = ground1 or bodyb = ground1
B2DELETEBODY bull(i).bodyID
bull(i).bodyID = 0
bull(i).shapeID = 0
bull(i).fixtureID = 0
bull(i).active = 0
bull(i).timer = 0
ENDIF
if bodya = ground2 or bodyb = ground2
B2DELETEBODY bull(i).bodyID
bull(i).bodyID = 0
bull(i).shapeID = 0
bull(i).fixtureID = 0
bull(i).active = 0
bull(i).timer = 0
ENDIF
endif
endif
inc bull(i).timer,1
if bull(i).timer > 100
B2DELETEBODY bull(i).bodyID
bull(i).bodyID = 0
bull(i).shapeID = 0
bull(i).fixtureID = 0
bull(i).active = 0
bull(i).timer = 0
ENDIF
ENDIF
next i
ENDFUNCTION
It makes no sense why it doesn't work. If you stop shooting then change weapon and start shooting again it works.
life is short but so am i