After fixing my other problem, timer-based movement began to make a lot more sense, so I used Dark Coder's little spiel (just because it looks flashy). Well, the "real" FPS (not
screen fps()) goes all over the place, between 1 and 70 (the Sync Rate and frame rate is set to 60). So as a result, I have my character jittering because the factor that determines his speed of travel is constantly varying widely, being 5 one millisecond and 65 the next.
Here are the functions, completely untouched:
//////////////////////////////////////////////////////////////////////
Function TBM_Init( TweenFrames As Integer ) //////////////////////////
// Failsafes
If TweenFrames <= 0
Exit Prompt "Variable 'TweenFrames' must be at least one." , "TBM_Init::Error"
End
Endif
// TweenFrames
Dim TBM_Tween( TweenFrames ) As Float
TBM_TotFrames = TweenFrames
// Get ticks per second
Load DLL "kernel32.dll", 1
Ptr = Make Memory(8)
Null = Call Dll(1, "QueryPerformanceFrequency", Ptr )
TimeGap = (*Ptr)
Delete DLL 1
// Failsafe for older CPUs
If TimeGap > 0
OldTime = Perftimer()
TBM_IsPerf = 1
Else
OldTime = Timer()
Endif
Endfunction //////////////////////////////////////////////////////////
Function TBM_Update() ////////////////////////////////////////////////
// Tween
Inc TBM_Frame
If TBM_Frame > TBM_TotFrames
TBM_Frame = 0
Endif
// Failsafe for older CPUs
If TBM_IsPerf
// Get Elapsed
FrameGap = Perftimer() - OldTime
OldTime = Perftimer()
// Tween
FrameGap = TBM_GetAverage( FrameGap )
// Get other variables
FPS = TimeGap / FrameGap
Elapsed = 1000 / FPS
Duration = Elapsed * 0.001
Else
// Get Elapsed
Elapsed = Timer() - OldTime
OldTime = Timer()
// Tween
Elapsed = TBM_GetAverage( Elapsed )
// Get other variables
FPS = Int( 1000 / Elapsed )
Duration = Elapsed * 0.001
Endif
Endfunction //////////////////////////////////////////////////////////
Function TBM_GetAverage( LatestElapsed As Integer ) //////////////////
Local ReturnValue As Float
// Add latest Elapsed
TBM_Tween(TBM_Frame) = LatestElapsed
// Find the average
For TBM = 0 To TBM_TotFrames
ReturnValue = ReturnValue + TBM_Tween(TBM)
Next TBM
ReturnValue = ReturnValue / ( TBM_TotFrames + 1 )
Endfunction ReturnValue //////////////////////////////////////////////
and here's the movement code:
Function PlayerMove(model as Integer, player_state as Integer)
` get the position of object 4
x# = object position x ( model )
y# = object position y ( model )
z# = object position z ( model )
rem Move player (eight-directional movement)
If Downkey()=1
If Leftkey()=1
yrotate object model,curveangle(45,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
else
If Rightkey()=1
yrotate object model,curveangle(-45,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
else
yrotate object model,curveangle(360,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
Endif
Endif
else
If Upkey()=1
If Rightkey()=1
yrotate object model,curveangle(-135,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
else
If Leftkey()=1
yrotate object model,curveangle(135,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
else
yrotate object model,curveangle(180,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
Endif
Endif
else
If Rightkey()=1
yrotate object model,curveangle(270,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
else
If Leftkey()=1
yrotate object model,curveangle(90,object angle y(model),10)
phy move character controller model, -50.0*Dn
player_state=1
else
player_state=0
endif
endif
endif
endif
rem END directional movement----------------------------------------------------
REM If player is moving, animate it
if player_state = 0
`Frame 173 - idle state
AnimFrame# = 173
set object frame model, AnimFrame#
else
if player_state = 1
`Frames 1 through 150 - walking state
if AnimFrame# = 0 then AnimFrame# = 1
if AnimFrame# > 150 then AnimFrame# = 1
TempFrame# = AnimSpeedMult# * ElapsedTime#
inc AnimFrame#, TempFrame#
set object frame model, AnimFrame#
endif:endif
`Move character controller back and forth to fall faster
phy move character controller model, 1 : phy move character controller model, -1
Endfunction
followed by a section of code from the main loop that updates the timer.
`Update Timer-Based Movement
TBM_update()
Dn=Duration*60
Is there a way to stop the jittering and make the movement smooth?
Currently working on - Enemy AI and Action Battle System
the sig limit needs to be raised...