Depending on the answers you may give, this thread is either going to be a
"here's all my source code - what's wrong?" thread, or a
"an almost complete flight model" thread.
Trouble is, I don't know what's wrong with it.
It's well commented to show where I'm having problems...
px,py,pz = position of heli
ax,ay,az = pitch, turn, roll of heli
sync on
sync rate 30
color backdrop rgb(0,0,0)
autocam off
backdrop on
hide mouse
gosub initGame
gosub declareGlobals
` -----------------------------------------------------------------------
px# = 10.0
pz# = 10.0
py# = 150.0
mouseSoftPX# = 0.0
mouseSoftPY# = 0.0
rollChangeAmount# = 0.0
pitchChangeAmount# = 0.0
turnChangeAmount# = 0.0
thrust# = 0.0
rotorSpin# = 0.0
`---------------------------------------------------------------------
do
gosub placeRotor
gosub handleKeys
` -------- these values are created in handleKeys... which uses the mouse :P
roll object left 1,rollChangeAmount#
pitch object up 1,pitchChangeAmount#
turn object left 1,turnChangeAmount#
` -------- az# is ALWAYS 0, WHY?
` -------- the model moves correctly, but this value isn't updated... ?!?!
ax# = object angle x(1)
ay# = object angle y(1)
az# = object angle z(1)
if (keystate(17) = 1):
thrust# = curvevalue(10.0, thrust#, 70);
else
thrust# = curvevalue(0.0, thrust#, 100)
endif
` --------- here, I'm trying to make a value so that when the heli is leaning forward,
` --------- we have a positive value, when leaning back, it's negative
speed# = 0.0
speed# = newxvalue(0.0, ax#, 1.0)
` --------- run-of-the-mill "move where I'm pointing" code... works fine
px# = newxvalue(px#, ay#, speed#*thrust#)
pz# = newzvalue(pz#, ay#, speed#*thrust#)
` ----- How can I take into account rollChangeAmount - the #az angle of the heli?
` ----- If I made another set of px#pz# coordinates, how would I combine the two?
` ----- also, changing the height of the heli realistically has me beat...
position object 1,px#, py#, pz#
set camera to follow px#, py#, pz#, object angle y(1), 200, py#+20, 10, 1
point camera px#, py#, pz#
debug()
sync
loop
function debug()
text 0,0, "ax : "+str$(ax#)
text 0,10, "ay : "+str$(ay#)
text 0,20, "az : "+str$(az#)
text 0,30, "speed : "+str$(speed#)
text 0,40, "thrust:"+str$(thrust#)
endfunction
placeRotor:
set object to object orientation 2,1
position object 2, px#, py#, pz#
`raise rotor
pitch object up 2,90
move object 2,65
pitch object down 2,90
`move it right
turn object right 2,90
move object 2, 10
turn object left 2,90
`move rotor towards front of model
move object 2, 40
`angle rotor
pitch object down 2, object angle z(1)
`spin rotor
turn object left 2, rotorSpin#
rotorSpin# = rotorSpin# + 50
return
handleKeys:
mouseSoftPX# = curvevalue(mousex()-(screen width() / 2), mouseSoftPX#, 1.3)
mouseSoftPY# = curvevalue(mousey()-(screen height() / 2), mouseSoftPY#, 1.3)
turnChangeAmount# = 0 - (mouseSoftPX#)/(screen width())*4.5
pitchChangeAmount# = (mouseSoftPY#)/(screen height())*4.5
if keystate(30) = 1 then rollChangeAmount# = curvevalue(2.0, rollChangeAmount#, 25)
if keystate(32) = 1 then rollChangeAmount# = curvevalue(-2.0, rollChangeAmount#, 25)
return
initGame:
make matrix 1,10000,10000,70,70
fog on
fog distance 5000
fog color 0,0,0
position matrix 1, -5000,0,-5000
randomize matrix 1,40
Load image "grass_T.bmp",1
load sound "heli.wav", 1
loop sound 1
Prepare matrix texture 1,1,1,1
update matrix 1
set text font "courier new"
set text size 16
set text transparent
load object "heli.x",1
color object 1, rgb(128,128,128)
load object "rotor.x",2
yrotate object 1,90
fix object pivot 1
fix object pivot 2
position mouse screen width()/2, screen height() / 2
return
declareGlobals:
global px# as float
global py# as float
global pz# as float
global ax# as float
global ay# as float
global az# as float
global mouseSoftPX# as float
global mouseSoftPY# as float
global rollChangeAmount# as float
global pitchChangeAmount# as float
global turnChangeAmount# as float
global thrust# as float
global speed# as float
return
If I've gone about it in the wrong way, lemme know and I'll start looking into doing it with vectors n junk..