Well, you could use mousehit(1) instead of mousedown(1). That would mean that you need to click the mouse button to get it to fire.
Or, you could create a timer for it. A little example program to show the timer in action and setting a range for the bullets. Hold in the mouse button to shoot :)
(Also, tidy up your house!)
Or, you could create a timer for it. A little example program to show the timer in action and setting a range for the bullets. Hold in the mouse button to shoot :)
(Also, tidy up your house!)
Graphics3D 800,600 SetBuffer BackBuffer() Global cam=CreateCamera() PositionEntity cam,0,0,-5 Global light=CreateLight() Global gun=CreateCube() ScaleEntity gun,0.3,0.3,3 PositionEntity gun,1,-1,0 Global main_bullet=CreateSphere(); create a bullter that the type objects can copy. ScaleEntity main_bullet,0.3,0.3,0.3 HideEntity main_bullet Type bullet Field entity Field speed# Field range Field pivot End Type Global gun_timer=MilliSecs() ; timer to track the difference in millisecs Global gun_time=200; time in milliseconds that the gun will fire While Not KeyHit(1) If MouseDown(1) And MilliSecs()>gun_time+gun_timer Then gun_timer=MilliSecs() ; reset the timer create_bullet(gun); call function to create a bullet. Pass across the gun entity to the function ; so the bullet can come from the guns position End If update_bullet() UpdateWorld RenderWorld Flip Wend End Function create_bullet(gun_entity) b.bullet=New bullet temp_x=EntityX(gun_entity,True) temp_y=EntityY(gun_entity,True) temp_z=EntityZ(gun_entity,True) b\entity=CopyEntity(main_bullet) ; copy the main bullet entity , into the type object b\pivot=CreatePivot() PositionEntity b\entity,temp_x,temp_y,temp_z RotateEntity b\entity,EntityPitch(gun_entity,True),EntityYaw(gun_entity,True),0 PositionEntity b\pivot,temp_x,temp_y,temp_z b\range=40 ; the range of the bullets b\speed=1 ; the speed of the bullets End Function Function update_bullet() For b.bullet = Each bullet MoveEntity b\entity,0,0,b\speed If EntityDistance#(b\entity,b\pivot) > b\range Then FreeEntity b\entity FreeEntity b\pivot Delete b.bullet End If Next End Function