Hi all,
I am using a function like this:
FUNCTION Turn_Ship(bot,x#,y#,z#,cycles,allowance#)
`store the bots current angles
botXA# = OBJECT ANGLE X(bot)
botYA# = OBJECT ANGLE Y(bot)
botZA# = OBJECT ANGLE Z(bot)
`rotate the bot to face the specified position
POINT OBJECT bot,x#,y#,z#
`store the bots new angles (z not required)
botNXA# = OBJECT ANGLE X(bot)
botNYA# = OBJECT ANGLE Y(bot)
`Check if the bot is already facing the direction specified (within allowance), if so
`skip the rest and return a completion point. Otherwise, continue with the
`calculations.
IF botXA# >= (botNXA#-allowance#) AND botXA# <= (botNXA#+allowance#) AND botYA# >= (botNYA#-allowance#) AND botYA# <= (botNYA#+allowance#)
hasturned = 1
Print "hasturned = " + str$(hasturned)
ELSE
`calculate the bots new angles
botXA# = CURVEANGLE(botNXA#,botXA#,cycles)
botYA# = CURVEANGLE(botNYA#,botYA#,cycles)
ENDIF
`re-rotate the bot
ROTATE OBJECT bot,botXA#,botYA#,botZA#
ENDFUNCTION hasturned
If I am turning my ship like this:
if mouseclick()=1
flag=pick object (mousex(),mousey(),grnd,grnd)
mx=get pick vector x()
my=get pick vector y()
mz=get pick vector z()
targetx=mx+camera position x()
targety=my+camera position y()
targetz=mz+camera position z()
position object mouse,targetx,targety,targetz
Turn_Ship(player,object position x(mouse),object position y(mouse),object position z(mouse),100,5)
endif
It will turn a long as I hold the mouse.
If I move my ship with this:
if mouseclick()=1
flag=pick object (mousex(),mousey(),grnd,grnd)
mx=get pick vector x()
my=get pick vector y()
mz=get pick vector z()
targetx=mx+camera position x()
targety=my+camera position y()
targetz=mz+camera position z()
position object mouse,targetx,targety,targetz
endif
Turn_Ship(player,object position x(mouse),object position y(mouse),object position z(mouse),100,5)
I will turn towards the "mouse object", and continue to point at the mouse object (if you have some speed to your ship, it will orbit the mouse object).
My qusetion is, How do I use the "hasturned" variable (returned by the function) to exit the function and maintain the current direction of travel (so my ship will go right past the mouse object, untill the next mouseclick to give it a new heading).
Thanks in advance for any help.
Mike
put this in your code snippets, code lang = dbp