Hello:
I am controlling 2 bullets with the mouse, one with the leftclick and the second one with the rightclick, and the target around the matrix with the mouse.
My big problem with the targeting system is that I want to shoot the first bullet at the target then have it go into a straight line towards the target, then move the target and not have the first bullet follow the target around when I re-target and shoot the second one, otherwise I have 2 bullets following the target around. Of course I want the bullets to come back to me. And I also have a small problem that when the bullets return, sometimes they just desapair.
This is my code so far..
` set up
autocam off
sync on
set display mode 800,600,16
` make floor
make matrix 1,500,500,20,20
` make target
make object box 1,20,20,5
` make player
make object cylinder 2,20
position object 2,250,1,250
` make fist bullet
make object sphere 3,10
color object 3,rgb(255,0,0)
` make second bullet
make object sphere 4,10
color object 4,rgb(0,255,0)
` position and point camera
position camera 250,300,-250
point camera 250,0,250
`initialize player position
playerx#=250
playerz#=250
`initialize mouse
x#=0:y#=0:z#=0
do
`print info on screen
set cursor 0,0 : print "leftclick= red bullet"
set cursor 0,15 : print "rightclick= green bullet"
set cursor 0,30 : print "mouse controls target"
set cursor 0,45 : print "cursor keys control the player"
`print sides
set cursor 350,190 : print "backside"
set cursor 350,500 : print "frontside"
set cursor 100,300 : print "leftside"
set cursor 650,300 : print "rightside"
`TARGETING
` initiate and calculate target y# position
y#=0
if shiftkey()=1 then y#=y#+100
if controlkey()=1 then y#=y#-100
` move along the bottom
if z# <=0
` to slow mouse movement divide mousemovex() by something
` x#=x#+(mousemovex()/5), to speed up, multiply
x#=x#-mousemovex():
if x# <= 0 then x#=0 : if x# >= 500 then x#=500
position object 1,x#,y#,0
endif
` move along left side
if x#<=0
` divide to slow, multiply to speed up
z#=z#+mousemovex()
if z# <=0 then z#=0
if z# >=500 then z#=500
position object 1,0,y#,z#
endif
` move along top
if z# >= 500
` divide to slow, multiply to speed
x#=x#+mousemovex()
if x# <= 0 then x#=0
if x# >= 500 then x#=500
position object 1,x#,y#,500
endif
` move along right side
if x#>=500
` divide to slow, multiply to speed up
z#=z#-mousemovex()
if z# >=500 then z#=500
if z# <=0 then z#=0
position object 1,500,y#,z#
endif
`1st bullet
` bullet creation
if mouseclick()=1 and BulletLife=0
` position bullet in the gun
position object 3,playerx#,1,playerz#
set object to object orientation 3,2
`Make it so the bullet is alive
bulletlife=1
show object 3
`Reset the FLAG value when you shoot, just in case.
hit=0
endif
`bullet path
if bulletlife>0
move object 3,10
`If the bullet has yet to hit the target, then make it point towards it
if hit=0
point object 3,object position x(1),object position y(1),object position Z(1)
endif
`If the bullet has already hit the target, make it point towards the player
if hit=1
point object 3,object position x(2),object position y(2),object position Z(2)
endif
endif
`Hide the bullet if it is not supposed to be visible
if bulletlife=0 then hide object 3
` collision detection
col_with_target=object collision(3,1)
`IT hit the target! Hit FLAG is now 1!
if col_with_target=1 and hit=0
Hit=1
endif
` collision detection with player
col_with_player=object collision(2,3)
`The bullet is done so kill and reset the flag.
if col_with_player=1 and Hit=1
BulletLife=0
Hit=0
endif
`2nd bullet object 4
` bullet creation
if mouseclick()=2 and BulletLife2=0
` position bullet in the gun
position object 4,playerx#,1,playerz#
set object to object orientation 4,2
`Make it so the bullet is alive
bulletlife2=1
show object 4
`Reset the FLAG value when you shoot, just in case.
Hit2=0
endif
`bullet path
if bulletlife2>0
move object 4,10
`If the bullet has yet to hit the target, then make it point towards it
if Hit2=0
point object 4,object position x(1),object position y(1),object position Z(1)
endif
`If the bullet has already hit the target, make it point towards the player
if Hit2=1
point object 4,object position x(2),object position y(2),object position Z(2)
endif
endif
`Hide the bullet if it is not supposed to be visible
if bulletlife2=0 then hide object 4
` collision detection
col_with_target2=object collision(4,1)
`IT hit the target! Hit FLAG is now 1!
if col_with_target2=1 and Hit2=0
Hit2=1
endif
` collision detection with player
col_with_player2=object collision(2,4)
`The bullet is done so kill and reset the flag.
if col_with_player2=1 and Hit2=1
BulletLife2=0
Hit2=0
endif
`player bounds
if playerx#<0 then playerx#=0
if playerx#>500 then playerx#=500
if playerz#<0 then playerz#=0
if playerz#>500 then playerz#=500
`player movements
if upkey()=1 then playerz#=playerz#+7
if downkey()=1 then playerz#=playerz#-7
if leftkey()=1 then playerx#=playerx#-7
if rightkey()=1 then playerx#=playerx#+7
`position everything
position object 2,playerx#,1,playerz#
`hide mouse
hide mouse
sync
loop
Can somebody help me please.