Want to show an example of the cheap direction method I mentioned cause it's a bit of an odd one. Figured I'll just make a simple 3rd person camera with smoothing to show it off:
sync on : sync rate 60
autocam off : hide mouse
color backdrop rgb(173,186,192)
rem set up player
playerSpeed# = 1.0
playerRotSpeed# = 2.0
playerLookSpeed# = 0.5
playerCameraSmoothing# = 0.1
playerCameraOffset# = 24
playerMinOffset# = 16
playerMaxOffset# = 64
playerHeight# = 16
playerHeightHalf# = playerHeight# * .5
playerID = 1
rem make player
make object sphere playerID, playerHeight#
scale object playerID, 50, 100, 50
position object playerID, 0, playerHeightHalf#, 0
rem make floor and texture it
cls rgb(128, 255, 255)
ink rgb(0, 128, 255),0
box 0,0,64,64 : box 64,64,128,128
ink rgb(255,255,255),0
get image 1,0,0,128,128,1
cls
make object box 2,512,4,512
position object 2,0,-2,0
texture object 2,0,1
scale object texture 2,16,16
do
rem store input data
_left = keystate(30) || leftkey()
_right = keystate(32) || rightkey()
_forward = keystate(17) || upkey()
_backward = keystate(31) || downkey()
_mouseVelocityY# = mousemovey()
_mouseVelocityZ# = mousemovez()
rem simple move and rotation of player
move object playerID, ( _forward - _backward ) * playerSpeed#
yrotate object playerID, wrapvalue( object angle y(playerID) + ( _right - _left ) * playerRotSpeed# )
rem update camera zooming
if _mouseVelocityZ# <> 0
playerCameraOffset# = clamp(( playerCameraOffset# - ( _mouseVelocityZ# * .02 )), playerMinOffset#, playerMaxOffset# )
endif
rem update camera rotation
cameraAngX# = cameraAngX# - (_mouseVelocityY# * .24)
cameraAngX# = clamp( cameraAngX#, -74, 74 )
rem cheap look/forward/direction vector with camera look direction
rem - basically this works a direction by shifting the object forward based on it's rotation
rem - and working out the difference between the old and new position.
oldPosX# = object position x(playerID) : oldPosY# = object position y(playerID) : oldPosZ# = object position z(playerID)
oldAngX# = object angle x(playerID) : oldAngY# = object angle y(playerID) : oldAngZ# = object angle z(playerID)
rotate object playerID, -cameraAngX#, oldAngY#, oldAngZ#
move object playerID, 1.0
directionX# = object position x(playerID) - oldPosX#
directionY# = object position y(playerID) - oldPosY#
directionZ# = object position z(playerID) - oldPosZ#
move object playerID, -1.0
rotate object playerID, oldAngX#, oldAngY#, oldAngZ#
rem offset our camera from
rem Position = Target - (Rotation * Offset)
newPositionX# = object position x(playerID) - (directionX# * playerCameraOffset#)
newPositionY# = object position y(playerID) + playerHeightHalf# - (directionY# * playerCameraOffset#)
newPositionZ# = object position z(playerID) - (directionZ# * playerCameraOffset#)
rem simple lerp
cameraPosX# = cameraPosX# + (newPositionX# - cameraPosX#) * playerCameraSmoothing#
cameraPosY# = cameraPosY# + (newPositionY# - cameraPosY#) * playerCameraSmoothing#
cameraPosZ# = cameraPosZ# + (newPositionZ# - cameraPosZ#) * playerCameraSmoothing#
rem finally update camera and stop it falling through the floor
position camera cameraPosX#, cameraPosY#, cameraPosZ#
if camera position y() < 2.0 then position camera camera position x(), 2, camera position z()
point camera object position x(playerID), object position y(playerID) + playerHeightHalf#, object position z(playerID)
text 12, 12, "WASD or Dir Buttons to move, Mouse to look up and down, Mouse Wheel to Zoom"
sync sleep 1
sync
loop
Just note, out of all the methods the matrix/vector one will be the fastest, second by trig math and then this method.
"Get in the Van!" - Van B