here is code I have so far for moving with wasd using a 3dphyics character control
repeat
Step3DPhysicsWorld()
check_lights()
Move3DPhysicsCharacterController( player, 0, walkVel#)
rem Old position
oldx#=GetCameraX(1)
oldy#=GetCameraY(1)-45.0
oldz#=GetCameraZ(1)
rem Move camera
if ( GetRawKeyState( 87 ) )
MoveCameraLocalZ( 1, 4 )
Move3DPhysicsCharacterController(player,1,walkvel#)
//print("Up")
endif
if ( GetRawKeyState( 83 ) )
MoveCameraLocalZ( 1, -4 )
Move3DPhysicsCharacterController(player,2,walkvel#)
// print("Down")
endif
if ( GetRawKeyState( 65 ) )
MoveCameraLocalX( 1, -4 )
Move3DPhysicsCharacterController(player,3,walkvel#)
// print("Left")
endif
if ( GetRawKeyState( 68 ) )
MoveCameraLocalX( 1, 4 )
Move3DPhysicsCharacterController(player,4,walkvel#)
// print("Right")
endif
if ( getvirtualbuttonstate(1) = 1 ) then MoveCameraLocalZ( 1, -4 )
if ( getvirtualbuttonstate(2) = 1 ) then MoveCameraLocalZ( 1, 4 )
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)
fDiffY# = (GetPointerY() - starty#)
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
Rotate3DPhysicsCharacterController(player,angy# + fDiffX#)
endif
if ( getrawjoystickexists(1) )
MoveCameraLocalZ(1,-getrawjoysticky(1)*4)
MoveCameraLocalX(1,getrawjoystickx(1)*4)
RotateCameraGlobalY(1,getrawjoystickrx(1)*4)
RotateCameraLocalX(1,getrawjoystickry(1)*4)
//RotateobjectGlobalY(player,GetCameraAngleX(1))
//Rotate3DPhysicsCharacterController(player,getcameraangleY(1))
endif `
rem Gravity on camera
SetCameraPosition(1,getobjectx(player),getobjecty(player),getobjectz(player))
//setobjectposition(gun,getobjectx(player),getobjecty(player),getobjectz(player))
rem New position
newx#=GetCameraX(1)
newy#=GetCameraY(1)-45
newz#=GetCameraZ(1)`
rem Adjust Y to match floor
pobj= ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,19.0)
if pobj>0
newx#=GetObjectRayCastSlideX(0)
newy#=GetObjectRayCastSlideY(0)
newz#=GetObjectRayCastSlideZ(0)
//SetCameraPosition(1,newx#,newy#+45.0,newz#)
//setobjectposition(player,newx#,newy#,newz#)
objc=GetObjectRayCastHitID(0)
endif
if objc<>0
//Print("hit object "+str(objc))
endif
posx# = sin(timer()*40) * 250 + 2000
SetPointLightPosition( 1, posx#, 565, -3600 )
//SetObjectPosition( 99, posx#, 565, -3600 )
rem Framerate prompt
// print("W A S D or joystick to move, click and drag to rotate")
fps=ScreenFPS() : Print("FPS: " + str(fps))
rem Update screen
if getrawkeypressed(KEY_E)
quit=1
endif
if getrawkeypressed(KEY_SPACE)
Jump3DPhysicsCharacterController(player)
endif
Sync()
until quit=1
Some of this code is used from examples in AppGameKit, what I want to know though is how do I display a gun and rotate /position it in front of the camwith this code,so it looks just like a typical first person shooter, tried some stuff but cannot get it right!
here is a video of the 3D level editor I have been developing for ages, :
just got some light effects coded,namely flicker/pusate or blinking... but really need a gun now, the code so far has been real simple as I am no good at maths atall!
Hail to the king, baby!