Yeah I can't figure out how to control the player properly? I've compared against the examples and can't see what could be wrong:
autocam off : set camera range 1,6000 : `hide mouse
global physics_engine : physics_engine = 1
gosub _physics_setup_env
Make Object box 1,2560,2560,2560
map_floor = 1 : position object map_floor,1280,-1280,1280
color object map_floor,rgb(0, 128, 64)
phy_floor = physics_create_floor(map_floor)
make object box 2,80,109,64
position object 2,250,250,250
player = 2
phy_player = physics_create_char(player)
sync on : sync rate 60
do
//VAR
px# = object position x(player)
py# = object position y(player)
pz# = object position z(player)
//CAM
position camera px#,py#+100,pz#
SET CAMERA TO OBJECT ORIENTATION player
move camera -250
gosub _physic_loop
sync
loop
_physics_setup_env:
if physics_engine = 1
NDB_Newtoncreate
NDB_SetVector 0.0, -9.8, 0.0 : NDB_SetStandardGravity
NDB_SetVector 1,-1280,-1,-1280 : NDB_SetVector 2,2560,2560,2560 : NDB_NewtonSetWorldSize
move_force#=100
endif
return
function physics_create_char(player)
px# = object position x(player)
py# = object position y(player)
pz# = object position z(player)
if physics_engine = 1
col=NDB_NewtonCreatebox(object size x(player),object size y(player),object size z(player))
phy_player = NDB_NewtonCreateBody(col)
NDB_BodySetDBProData phy_player,player
NDB_NewtonBodySetMassMatrix phy_player, 100
NDB_BodySetGravity phy_player,1
NDB_NewtonBodySetAutoFreeze phy_player,0
//TODO object angle
NDB_BuildMatrix 0.0, 0.0, 0.0, px#,py#,pz#
NDB_NewtonBodySetMatrix phy_player
NDB_NewtonReleaseCollision col
NDB_SetVector 0,1,0
UpvectorJoint = NDB_NewtonConstraintCreateUpVector( phy_player )
//TODO material
endif
endfunction phy_player
function physics_create_floor(floorobj)
if physics_engine = 1
col = NDB_NewtonCreateBox( object size x(floorobj),object size y(floorobj),object size z(floorobj) )
phy_floor = NDB_NewtonCreateBody( col )
NDB_BuildMatrix 0.0, 0.0, 0.0, 1280.0, -1280.0, 1280.0
NDB_NewtonBodySetMAtrix phy_floor
NDB_BodySetDBProData phy_floor, floorobj
endif
endfunction phy_floor
function physics_create_box()
if physics_engine = 1
endif
endfunction
_physic_loop:
if physics_engine = 1
Rem Here we set the forces on the fps object (Movement)
Rem The first vector 1 is in this case (NDB_BodyAddForceLocal) saying
Rem WHERE on the fps object the force will be set.
Rem I have made a slight offset in the direction of the front of the object
Rem Which I will use to make the object turn. (I am making sure that
Rem the forces will be pushing it on the 'nose')
Rem (0.3 units in the Z direction, object front direction)
NDB_SetVector 1,0,0,0.0.3
NDB_SetVector 2,0,0,0
if upkey() then NDB_SetVector 2,0,0,move_force#
if downkey() then NDB_SetVector 2,0,0,-move_force#
if leftkey() then NDB_SetVector 2,-move_force#,0,0
if rightkey() then NDB_SetVector 2,move_force#,0,0
if spacekey() then NDB_SetVector 2,0,move_force#,0
NDB_BodyAddForceLocal phy_player
if controlkey() then NDB_DebugDrawNewtonLines
time# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate time#
endif
return