This code works, I added some third person controls, a cube for the player, and a floor with some basic collision.
I might have changed to much, but its not a bad example of moving a character around, in third person.
And the player moves just fine in the air.
You might want to change the controls, depending on what kind of game your making.
Hope this helps.
sync on
hide mouse
`start on the ground
Global Jumping As boolean
Jumping = 0
Global JumpPower# As Float
JumpPower# = 1.5 `The stength of the players jump
Global GravityPll# As Float
GravityPll# = 0.025 `The strength of the gravity
Rem player position and angle variables
Global P1X# As Float
Global P1Y# As Float
Global P1Z# As Float
Global A1Y# As Float
color backdrop 0 `creates a black background
Rem Create a checker pattern texture
ink RGB(128,128,128),0 : box 0,0,1,1
ink RGB(192,192,192),0 : dot 0,0 : dot 1,1
get image 1,0,0,2,2,0
Rem Create a subject object
make object cube 1,1 : move object up 1,0.5
Rem Creates the endless checker floor
make object plain 2,1000,1000 : pitch object down 2,90
set object light 2,0 : set object filter 2,0
texture object 2,1 : scale object texture 2,25,25
Rem main loop
Do
Rem Mouse controls
MMX# = MouseMoveX() : MMY# = MouseMoveY()
CAX# = CAX# + MMY#
CAY# = CAY# + MMX#
if CAX# > 90 then CAX# = 90 `cameras maximum angle
if CAX# < 10 then CAX# = 10 `cameras minimum angle
Rem turns the player
rotate object 1,0,A1Y#,0
`turn object right 1,CAY#
rotate camera 0,CAX#,CAY#,0
if CAY# > A1Y# then inc A1Y#,.1
if CAY# < A1Y# then dec A1Y#,.1
if CAY# > A1Y#+1 then inc A1Y#,1
if CAY# < A1Y#-1 then dec A1Y#,1
if CAY# > A1Y#+10 then A1Y# = CAY#-10
if CAY# < A1Y#-10 then A1Y# = CAY#+10
Rem Slow the player to a stop when the player is not moving
N# = 1
for i = 1 to 8
N# = N# * 40 `this number can be increased to add more of a slide effect
if P1SpeedZ# > 1/N# then P1SpeedZ# = P1SpeedZ# - 1/N#
if P1SpeedZ# < -1/N# then P1SpeedZ# = P1SpeedZ# + 1/N#
if P1SpeedX# > 1/N# then P1SpeedX# = P1SpeedX# - 1/N#
if P1SpeedX# < -1/N# then P1SpeedX# = P1SpeedX# + 1/N#
next i
Rem Control the movement of the player with the arrow keys
if UpKey() = 1 then Inc P1SpeedZ#,.25
if DownKey() = 1 then Dec P1SpeedZ#,.25
if RightKey() = 1 then Inc P1SpeedX#,.25
if LeftKey() = 1 then Dec P1SpeedX#,.25
Rem Puts a limit on the players speed
if P1SpeedZ# > 1 then P1SpeedZ# = 1
if P1SpeedZ# < -1 then P1SpeedZ# = -1
if P1SpeedX# > 1 then P1SpeedX# = 1
if P1SpeedX# < -1 then P1SpeedX# = -1
dec P1SpeedY#,GravityPll# `Gravity
Rem if the player is on solid ground and clicks the mouse then make the player jump
if mouseclick() = 1 and Jumping = 0
P1SpeedY# = JumpPower#
endif
Jumping = 1 `sets Jumping to 1 so that the player cannot jump in midair
Rem Moves the Player
move object 1,P1SpeedZ#/2 `forwards and backwards
move object right 1,P1SpeedX#/3 `right and left
move object up 1,P1SpeedY# `gravity
Rem Gets the players positions
P1X# = object position x(1)
P1Y# = object position y(1)
P1Z# = object position z(1)
Rem Detects collision with the floor
if P1Y# < 0.5
position object 1,P1X#,0.5,P1Z#
Jumping = 0
P1SpeedY# = 0
endif
Rem Makes the floor follow the player
if P1X# > object position x(2)+20 then move object left 2,40
if P1X# < object position x(2)-20 then move object right 2,40
if P1Z# > object position z(2)+20 then move object down 2,40
if P1Z# < object position z(2)-20 then move object up 2,40
position camera 0,P1X#,P1Y#,P1Z# `positions the camera
Rem this makes the game third person
move camera 0,-10 `The radius/distance between the camera and the player
`render
Sync
Loop
End
I like games, and stuff.