@SvenB:
I still haven't been able to get this to work properly.
I have to admit, I did get fed up and leave it alone for a little while and worked on other things.
But have been trying again the last few days but to no avail.
//********************************************
// Variables and ting
//********************************************
#constant vectorPosition 1
#constant vectorVelocity 2
#constant vectorAcceleration 3
`#constant vectorDrag 4
#constant playerHeight 5
type dPlayer
shipObj as integer
acc as float
drag as float
lookAngle as float
endtype
type dTBM
start as integer
finish as integer
move as float
endtype
dim tbm(0) as dTBM
dim player(0) as dPlayer
null=make vector2(vectorPosition)
null=make vector2(vectorVelocity)
null=make vector2(vectorAcceleration)
`null=make vector2(vectorDrag)
player(0).shipObj=1
player(0).acc=0.05:` 15000:`0.05
`player(0).drag=0.05 : ` tried 0.001 to 15000 nothing seems to change it
//********************************************
// system stuff
//********************************************
sync rate 60
sync on
autocam off
//********************************************
// create & position media
//********************************************
` player
make object box player(0).shipObj,10,10,20
position object player(0).shipObj,0,playerHeight,0
color object player(0).shipObj,rgb(255,0,0)
` ground
make object plane 4,500,500
position object 4,0,0,0
xrotate object 4,-90
color object 4,rgb(0,255,0)
` camera
position camera 0,0,500,0
point camera 0,0,0,0
//********************************************
// main loop
//********************************************
do
thrust=0 : ` not thrusting
updateTBM()
` Control the spaceships rotation
If LeftKey()
dec player(0).lookAngle,180*tbm(0).move
endif
If RightKey()
inc player(0).lookAngle,180*tbm(0).move
endif
If upkey()
thrust=1
EndIf
If downkey()
thrust=-1
EndIf
// physics
` part 1
x#=sin(player(0).lookAngle)*(player(0).acc*thrust)
z#=cos(player(0).lookAngle)*(player(0).acc*thrust)
set vector2 vectorAcceleration,x#,z#
` part 2
`multiply vector2 vectorAcceleration,tbm(0).move
add vector2 vectorVelocity,vectorVelocity,vectorAcceleration
` part 3
`multiply vector2 vectorVelocity,tbm(0).move
add vector2 vectorPosition,vectorPosition,vectorVelocity
// finally updates the object
position object player(0).shipObj,x vector2(vectorPosition),playerHeight,y vector2(vectorPosition)
yrotate object player(0).shipObj,player(0).lookAngle
// draws the Debug info to screen
drawDebug()
// updates the screen
sync
loop
end
//********************************************
// functions
//********************************************
//********************************************
// on screen debug information
//********************************************
function drawDebug()
local currentLine as integer : currentLine=0
local textSize as integer : textSize=text size()
text 0,textSize*currentLine,"FPS: "+str$(screen fps()) : inc currentLine,2
text 0,textSize*currentLine,"Player Data" : inc currentLine,1
text 0,textSize*currentLine,"vVelocity: "+str$(length vector2(vectorVelocity)) : inc currentLine,1
text 0,textSize*currentLine,"vPosition: "+str$(length vector2(vectorPosition)) : inc currentLine,1
`text 0,textSize*currentLine,"vForce: "+str$(length vector2(vectorForce)) : inc currentLine,1
text 0,textSize*currentLine,"vAcceleration: "+str$(length vector2(vectorAcceleration)) : inc currentLine,1
`text 0,textSize*currentLine,"InertiaZ: "+str$(player(0).inertiaZ) : inc currentLine,1
endfunction
//**********************************************************************
// This updates the TBM stuff
//**********************************************************************
function updateTBM
if tbm(0).start=0
tbm(0).start=hiTimer()
else
tbm(0).finish=hiTimer()
tbm(0).move=(tbm(0).finish-tbm(0).start)/1000.0
tbm(0).start=hiTimer()
endif
endfunction
The code above works as expected; with the ship accelerating when thrust is applied, and conitinuing uninterupted until you thrust again.
However, when you uncomment the 2 lines where the Timer Based Movement factor is applied to the vectors (And change the value for acceleration); then the ship stops when your not thrusting.
I've removed all the collision and drag stuff for the time being until I can get this issue sorted. (Initially, I thought I was doing the drag wrong, and wasted many hours trying to rectify that)
Can you (or anyone else) see where have I gone wrong?
Thanks as always
=PRoF=
>edit<
Removed some stuff from the code from when I was trying with hidden objects instead of vectors