This uses Lee's code for controller forward#,backward# but when going backward or left
it won't loose altitude because negative values are upward.
Notice you no longer need
PHY Set Character Controller Displacement 2, 0, MCKey * 1000.0
and only a small value is needed to go up and down since we set the
value to -200 just after creating the character controller earlier
in the code.
Might say too that the value MCKey would not cause the up action
because it needs a floating number. Hence the -1.0 and 1.0 for
up and down.
Rem Project: Jump_Forum
Rem Created: 8/29/2006 7:19:02 PM
Rem ***** Main Source File *****
` DBP Setup.
autocam off
sync on
sync rate 60
Color Backdrop 0
`backdrop off
` Initialize PhysX Engine.
phy start
phy set gravity 0, -9.81, 0
` Create the ground.
make object plain 1, 30000, 30000
color object 1, rgb(20, 120, 20)
xrotate object 1, -90
phy make rigid body static box 1
` Create the player.
make object box 2, 100, 100, -200
phy make box character controller 2, 100, 100, -200, 10, 50, 10, 1, 16, 45
hide object 2
phy set character controller displacement 2,200,-200
char_height#=50.0
rem a few boxes
for boxes = 3 to 20
make object box boxes, 20, 20, 20
position object boxes, 30 * boxes, 60, 0
color object boxes, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127))
phy make rigid body dynamic box boxes
phy set rigid body mass boxes, 1000.0
next boxes
Repeat
` GET INFORMATIONS ON ENTRIES TO MAKE CHANGES ON PLAYER
UDKey = UpKey() - DownKey() ` Forward/Backward
LRKey = RightKey() - LeftKey() ` Strafe Right/Left
MCKey = 0 - MouseClick() ` Jump
` Rotate the player using mouse movements.
oldcamx = camx : camx = wrapvalue( camx + mousemovey() * 0.4 )
oldcamy = camy : camy = wrapvalue( camy + mousemovex() * 0.4 )
yrotate object 2, curveangle( camy, oldcamy, 24 )
` Move player Forward/Backward
If UDKey <> 0
PHY Move Character Controller 2, UDKey * 200.0
Endif
` Player Strafe Right/Left
If LRKey <> 0
YRotate Object 2, WrapValue( CamY + ( 90 + LRKey ) )
PHY Move Character Controller 2, LRKey * 100.0
YRotate Object 2, WrapValue( CamY )
endif
If MCKey <> 0
PHY Move Character Controller 2,-1.0
else
PHY Move Character Controller 2,1.0
endif
PHY Update
` Update the camera to go where the player is.
position camera object position x(2), object position y(2) + 20, object position z(2)
rotate camera object angle x(2), object angle y(2), object angle z(2)
Sync
Until SpaceKey() = 1
Ad Astra Per Asper