Hello
Sorry for weird title, no idea how I should put it.
I have some code that moves the camera around with mouse + keyboard:
camY As Float
camY = GetCameraY(1)
MoveCameraLocalX(1, GetJoystickX()*5)
MoveCameraLocalZ(1, -GetJoystickY()*5)
SetCameraPosition(1, GetCameraX(1), camY, GetCameraZ(1))
// rotate the camera
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
Works like a charm when I put this in the main loop.
But when I put that in a function, and call that function in the mainloop, like this:
do
Print(ScreenFPS())
Print(LastString)
If(GetSocketBytesAvailable(1) > 0)
LastString = ParseCommands(GetSocketString(1))
EndIf
input()
Sync()
loop
Function input()
camY As Float
camY = GetCameraY(1)
MoveCameraLocalX(1, GetJoystickX()*5)
MoveCameraLocalZ(1, -GetJoystickY()*5)
SetCameraPosition(1, GetCameraX(1), camY, GetCameraZ(1))
// rotate the camera
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
EndFunction
The mouseinput is registered wrong, when I click, the camera is repositioned seemingly arbitrairarly, but it works when I move and click, but on the next click, the camera is again repositioned.
Why does this code behave different when put in a function?
Sorry if this is a stupid question, I'm really a beginner.
Thanks!