ok this isn`t complet but I add this bit of code I hope it helps, the fished bit will be added to dark physic & AI challeneg post
sorry its the code is a bit slopy but here it is.
sync on : sync rate 60
set camera range 1,1000
set normalization on
` make some default values
remstart
if default = 0
player_walking = 1
player_running = 0
default = 1
endif
remend
`PHY ENABLE DEBUG
phy start
` make land
land_test()
gosub player_type_setup
` make new player object
make object box 2, Player.width#, Player.height#, Player.width#
`*** make object for player collision *** add this pace of code latter
remstart
` make new player collision object
make object box 3,Player.width#, Player.height#, Player.width#
scale object 3,100,50,100
hide object 3
remend
` make player physics
player_stand() :` make physic for player object stand
`player_crouch() :` make physic for player object crouch
do
` player controls
gosub player_control
` this is a temp
if scancode()=2
gosub camera_rotation
else
gosub camera_on_player
endif
phy update
sync
loop
phy end
end
`*********************************************************
`*******************(1st Person Camera)******************
`*********************************************************
`=== note to self, make 3rd person camera veiw to ===
` set up player camera control
camera_on_player:
` stops players mouse movement from going upside down
if Player.angx# >=100 and Player.angx# <=120 then Player.angx# = 100
if Player.angx# >=180 and Player.angx# <=280 then Player.angx# = 280
` running bob
if run_on = 1 :`player_running =1
` make camera bob up and down
camerabob# = wrapvalue( camerabob# + (Player.speed# ) )
cam_bobY# = cos( camerabob# ) *0.05
` play walk sound to be added here
endif
` walking bob
if run_on = 0 :`player_walking =1
` make camera bob up and down
camerabob# = wrapvalue( camerabob# + (Player.speed# ) )
cam_bobY# = cos( camerabob# ) *0.025
` play walk sound to be added here
endif
if run_on = 2 then cam_bobY# = curvevalue( 0.0, cam_bobY#, 10.0 )
` update run state
if run_on = 1 :`player_running = 1
` update camera positions
camera_xcam# = Player.Xpos# + cam_bobY# / 4 :` added this to my camera bob to make the run look more action based
camera_ycam# = Player.Ypos# + cam_bobY#
camera_zcam# = Player.Zpos# + cam_bobY# / 4 :` added this to my camera bob to make the run look more action based
endif
` update walik state
if run_on = 0 :`player_walking = 1
`if scancode() = 0 then cam_bobY# = 0.0
` update camera positions
camera_xcam# = Player.Xpos#
camera_ycam# = Player.Ypos# + cam_bobY#
camera_zcam# = Player.Zpos#
endif
` update stop state
if run_on = 2 :`player_stop = 1
` update camera position
camera_xcam# = Player.Xpos#
camera_ycam# = Player.Ypos# + cam_bobY#
camera_zcam# = Player.Zpos#
endif
` position & rotate camera acording to mouse move & object position
position camera 0,camera_xcam#,camera_ycam#,camera_zcam#
rotate camera 0,Player.angx#,Player.angy#,0.0
return
`*********************************************************
`********************( Player Controls )******************
`*********************************************************
`*** control player object ***
player_control:
` mouse move input
Player.mouseMovementX# = mousemovex() / 2
Player.mouseMovementY# = mousemovey() / 2
`Turn player acording to mouse movement
Player.angy# = wrapvalue(Player.angy# + Player.mouseMovementX#*Player.lookSpeed#)
Player.angx# = wrapvalue(Player.angx# + Player.mouseMovementY#*Player.lookSpeed#)
` keeps character in contact with scene
movementshifter#=wrapvalue(movementshifter#+0.00000001*(60.0/screen fps()))
Player.movement#=cos(movementshifter#)/80.0
` use shift to walk / run
if shiftkey()=1
Player.speed# = 37.5*(60.0/screen fps())
run_on = 1 : `use this to set camera bob type
else
Player.speed#=18.5*(60.0/screen fps())
run_on = 0
endif
` set up none camera bob settings
if upkey()=0 and KeyState(17)=0 and downkey()=0 and KeyState(31)=0 and leftkey()=0 and KeyState(30)=0 and rightkey()=0 and KeyState(32)=0
run_on = 2
endif
` player object angles
Player.play_angX# = object angle x(2)
Player.play_angY# = object angle y(2)
Player.play_angz# = object angle z(2)
` use WASD to move player
if upkey() = 1 or KeyState(17) = 1 then Player.movement#=Player.speed#
if downkey() = 1 or KeyState(31) = 1 then Player.movement#=0.0-Player.speed#
if leftkey()=1 or KeyState(30) = 1 then yrotate object 2,Player.play_angY#-90 : phy move character controller 2,Player.speed# : yrotate object 2,Player.play_angY#
if rightkey()=1 or KeyState(32) = 1 then yrotate object 2,Player.play_angY#+90 : phy move character controller 2,Player.speed# : yrotate object 2,Player.play_angY#
` rotate player object acording to camera y rotation
yrotate object 2,Player.angy#
rem Always move the character, even if still
walkstep#=wrapvalue(walkstep#+(Player.movement#/4.0))
phy move character controller 2,Player.movement#
` find out the players position
Player.Xpos# = object position x(2)
Player.Ypos# = object position y(2)
Player.Zpos# = object position z(2)
position object 2,Player.Xpos#,Player.Ypos#,Player.Zpos#
` update player old position
` this is so apone crouching the player gets kicked up, to stop him falling threw the ground
player.old_Xpos# = Player.Xpos#
player.old_Ypos# = Player.Ypos#
player.old_Zpos# = Player.Zpos#
` this is use to move the ray back and forth
if ray_move_plus = 0 then rmp = 0
if ray_move_plus = 4 then rmp = 1
if rmp = 0 then inc ray_move_plus
if rmp = 1 then dec ray_move_plus
if ray_move_minus = 0 then rmm = 0
if ray_move_minus = -4 then rmm = 1
if rmm = 0 then dec ray_move_minus
if rmm = 1 then inc ray_move_minus
swich_ray = rnd(1)+1
if swich_ray = 1 then sray = ray_move_plus
if swich_ray = 2 then sray = ray_move_minus
rayC# = wrapvalue( rayC# + 20.0 )
rayX# = cos ( rayC# ) * sray :`8.0 keep this as a smaller value
rayZ# = sin ( rayC# ) * sray :`10.0 kepp this as a bigger value
` to test to see if the player is close to an object, so the player can jump again
if up_down_ray = 0
value = phy ray cast all shapes (Player.Xpos#,Player.Ypos#,Player.Zpos#,0,0,0)
endif
if up_down_ray = 1
value = phy ray cast all shapes (Player.Xpos#+rayX#,Player.Ypos#,Player.Zpos#+rayZ#,0,-1,0)
endif
if up_down_ray = 2
value = phy ray cast all shapes (Player.Xpos#+rayX#,Player.Ypos#,Player.Zpos#+rayZ#,0,1,0)
endif
dist# = phy get ray cast distance()
ink rgb(0,0,0),0 :`colour text black so you can see it on any
set cursor 0,0 : print "get the height of the floor: ";dist#
set cursor 0,10 : print "player object height: ";Player.Ypos#
` make green ray cast object
if object exist (1) = 0
make object sphere 1,1
color object 1,rgb(0,255,0)
set object specular 1, rgb ( 0, 255, 0 )
set object specular power 1, 255
set object ambient 1,0
endif
if object exist (1) = 1
position object 1, phy get ray cast hit point x ( ) ,phy get ray cast hit point y ( ),phy get ray cast hit point z ( )
endif
` player jump
if spacekey()=1 or keystate(57)=1 and spacekeypress = 0
spacekeypress = 1
up_down_ray = 1 :` this is so you can chamge what time of ray casting you wont
if jumping = 1 then jumping = 0 else jumping = 1
endif
if jumpingOLD <> jumping
if jumpingOLD < jumping
if dist# < 5.2 :` replacement value, old value 20.5, new value 5.0
player_jump()
set cursor 0,20 : print "Ok"
else
set cursor 0,20 : print "None"
endif
endif
jumpingOLD = jumping
endif
if spacekey()=0 or keystate(57)=1 then spacekeypress = 0
` player crouch
If KeyState(29) = 1 and keystate29 = 0
keystate29 = 1
up_down_ray = 2 :` this is so you can chamge what time of ray casting you wont
if crouching = 1 then crouching = 0 else crouching = 1 :` on / off switch crouch
endif
if crouchOLD <> crouching
if crouchOLD < crouching
player_crouch() :`switch to the crouch function
else
player_stand() :`switch to the stand function
endif
crouchOLD = crouching
endif
if KeyState(29) = 0 then keystate29 = 0
` position players collision box, add this in latter
`phy set rigid body kinematic position 3,Player.Xpos#,Player.Ypos#+10.0,Player.Zpos#
return
`*********************************************************
`********************( Player Values )********************
`*********************************************************
`*** set up player values ***
player_type_setup:
` player type
type player_type
` player speed
speed# as float
` camera xyz angle
angx# as float
angy# as float
angz# as float
` player xyz angle
play_angX# as float
play_angY# as float
play_angZ# as float
` player xyz position
Xpos# as float
Ypos# as float
Zpos# as float
` player old xyz position
old_Xpos# as float
old_Ypos# as float
old_Zpos# as float
` player mouse move xy
mouseMovementX# as float
mouseMovementY# as float
` player look speed
lookSpeed# as float
` player width and height
width# as float
height# as float
` player how high steps are
steps# as float
` player slopes
slope_limit# as float
`
energy# as float
`
mass# as float
`
speed# as float
`
MoveX# as float
MoveZ# as float
`
movement# as float
endtype
global Player as player_type :` add type values
`*** player starts out put ***
Player.LookSpeed# = 0.2
Player.mass# = 12.0
player.MoveX# = 0.00
player.MoveZ# = 0.00
Player.width# = 5.0
Player.height# = 10.0
Player.steps# = 1.5
Player.slope_limit# = 45.0
player.old_Xpos# = 0.0
player.old_Ypos# = 10.0
player.old_Zpos# = 0.0
return
`*********************************************************
`********************( Temp Landscape )*******************
`*********************************************************
`*** make a tempary land ***
function land_test()
make object cube 1000,1
scale object 1000,5000,10,5000
make mesh from object 1,1000
delete object 1000
make object 1000,1,0
delete mesh 1
make object cube 3,1
make mesh from object 1,3
delete object 3
for c = 1 to 4
add limb 1000,c,1
`scale limb 1000,c,10,5000,10
scale limb 1000,c,400,400,400
next c
offset limb 1000,1,20,-0.5,20 :` I`v adusted this one to make it more like a 1.5 step,
color limb 1000,1,rgb(255,0,0) :` I`v coloured this limb red so that I know whitch one is position in a diferent place.
offset limb 1000,2,-20,2.0,-20
offset limb 1000,3,-20,2.0,20
offset limb 1000,4,20,2.0,-20
delete mesh 1
`====================start steps=====================
` make mesh and an object to work from
make object cube 3,1
make mesh from object 1,3
position object 3,0,-9,10
` make steps
for c = 1 to 13
add limb 3,c,1
rotate limb 3,c,45,0,0
offset limb 3,c,0,0,c+1.25
scale limb 3,c,100,100,100
next c
` make mesh of brackits
make mesh from object 1,3
delete object 3
` left steps floor strucher *
add limb 1000,5,1
scale limb 1000,5,1200,200,200 :`200,10,650
offset limb 1000,5,0,-2.75,-21 :`-3.5,3.725,0
rotate limb 1000,5,-45,180,0
color limb 1000,5,rgb(0,0,255)
`hide limb 1,15 :`temp
` delete mesh
delete mesh 1
`======================end steps=======================
`====================start door======================
` make mesh and an object to work from
make object cube 3,1
make mesh from object 1,3
position object 3,0,-9,10
` make a door piller top
for c = 1 to 2
add limb 3,c,1
scale limb 3,c,75,75,75
next c
for c = 3 to 4
add limb 3,c,1
scale limb 3,c,50,50,50
next c
offset limb 3,1,1.25,0,0
offset limb 3,2,-1.25,0,0
offset limb 3,3,0.75,0,0
offset limb 3,4,-0.75,0,0
hide limb 3,0
` delete mesh
delete mesh 1
` make mesh of blocks
make mesh from object 1,3
delete object 3
` add door detal top, top floor back door
add limb 1000,6,1
scale limb 1000,6,400,400,400
offset limb 1000,6,0,13.5,15
color limb 1000,6,rgb(0,255,0)
` delete mesh
delete mesh 1
` make mesh and an object to work from
make object cube 3,1
make mesh from object 1,3
position object 3,0,-9,10
` make door piller sides
for c = 1 to 4
add limb 3,c,1
scale limb 3,c,75,75,75
next c
for c = 5 to 6
add limb 3,c,1
next c
offset limb 3,1,0,0.75,0
offset limb 3,2,0,2,0
offset limb 3,3,0,-0.75,0
offset limb 3,4,0,-2,0
offset limb 3,5,0,1.25,0
offset limb 3,6,0,-1.25,0
` make mesh of blocks
make mesh from object 1,3
delete object 3
` add door piller sides
for c = 7 to 8
add limb 1000,c,1
scale limb 1000,c,275,275,275
next c
offset limb 1000,7,5,6,15
offset limb 1000,8,-5,6,15
color limb 1000,7,rgb(0,255,0)
color limb 1000,8,rgb(0,255,0)
` delete mesh
delete mesh 1
`=====================end door=======================
`=====================start slop=======================
` make mesh and an object to work from
make object cube 3,1
make mesh from object 1,3
delete object 3
` add slop limb
add limb 1000,9,1
scale limb 1000,9,5000,10,2500
rotate limb 1000,9,45.0,0,0
offset limb 1000,9,0,8.5,-32.75
` delete mesh
delete mesh 1
`=====================end slop=======================
`=====================start wall=======================
` make mesh and an object to work from
make object cube 3,1
make mesh from object 1,3
delete object 3
` add wall limb
add limb 1000,10,1
scale limb 1000,10,5000,2500,10
rotate limb 1000,10,0,90,0
offset limb 1000,10,-25,12.5,0
` add rooth limb
add limb 1000,11,1
scale limb 1000,11,5000,10,5000
offset limb 1000,11,0,25,0
` add crouch height limb
add limb 1000,12,1
color limb 1000,12,rgb(127,127,0)
scale limb 1000,12,1000,100,5000
offset limb 1000,12,-20,7.25,0
` delete mesh
delete mesh 1
`=====================end wall=======================
position object 1000,0,-15,0
phy make rigid body static mesh 1000,"test_level_03.x"
phy load rigid body static mesh 1000,"test_level_03.x"
set object specular 1000, rgb ( 255, 255, 255 )
set object specular power 1000, 255
set object ambient 1000,0
endfunction 1000
`*********************************************************
`***************( Temp 3rd Persone Camera )***************
`*********************************************************
` camera rotation control for over view. temp
camera_rotation:
` camera rotates around test aera
c# = wrapvalue( c# + 0.5 )
x# = cos ( c# ) * 40.0 :`8.0 keep this as a smaller value
z# = sin ( c# ) * 50.0 :`10.0 kepp this as a bigger value
position camera x#, 4, z#
point camera 0.0,4,0.0
return
`*********************************************************
`***************( make a standing player )****************
`*********************************************************
`*** make player stand ***
function player_stand()
`*** setup info height ***
` set up character controller height
Player.height# = 10.0
`*** make object for player control ***
` scale player object
scale object 2,100,100,100
` test to see if our character controller exists or not
if phy get character controller exist (2) = 1
` delete character controller
phy delete character controller 2
endif
` create new character controller including stand values
phy make box character controller 2,player.old_Xpos#,player.old_Ypos#+1.0,player.old_Zpos#, Player.width#/2, Player.height#/2,Player.width#/2, 1, Player.steps#, Player.slope_limit#
`*** make object for player collision *** add this pace of code latter
remstart
` make new player collision object
make object box 3,Player.width#, Player.height#, Player.width#
scale object 3,100,100,100
hide object 3
`test to see if our physic collision object exists or not
if phy get rigid body exist (3) = 1
` delete rigid body
phy delete rigid body 3
endif
` make new player collision physic
phy make rigid body dynamic box 3
phy set rigid body kinematic 3,1
remend
endfunction
`*********************************************************
`***************( make a crouching object )****************
`*********************************************************
`*** make player crouch ***
function player_crouch()
`*** setup info height ***
` set up character controller height
Player.height# = 5.0
`*** make object for player control ***
` scale player object
scale object 2,100,50,100
` test to see if our character controller exists or not
if phy get character controller exist (2) = 1
` delete character controller
phy delete character controller 2
endif
` create new character controller including crouch values
phy make box character controller 2,player.old_Xpos#,player.old_Ypos#,player.old_Zpos#, Player.width#/2, Player.height#/2,Player.width#/2, 1, Player.steps#, Player.slope_limit#
remstart
`add this pace of code latter
scale physic object
scale object 3,100,50,100
`test to see if our physic collision object exists or not
if phy get rigid body exist (3) = 1
` delete rigid body
phy delete rigid body 3
endif
` make new player collision physic
phy make rigid body dynamic box 3
phy set rigid body kinematic 3,1
remend
endfunction
`*********************************************************
`****************( make a jumping object )****************
`*********************************************************
`*** make player Jump ***
function player_jump()
`*** setup info height ***
` set up character controller height
Player.height# = 10.0
` set energy to object
Player.energy# = 10.0 :`wrapvalue(Player.mass# + Player.speed#)
`Player.energy# = Player.mass# + Player.speed#
`set cursor 0,10 : print Player.energy#
` test to see if our character controller exists or not
if phy get character controller exist (2) = 1
` delete character controller
phy delete character controller 2
endif
` create new character controller including jump values
phy make box character controller 2,player.old_Xpos#,player.old_Ypos#+Player.energy#,player.old_Zpos#, Player.width#/2, Player.height#/2,Player.width#/2, 1, Player.steps#, Player.slope_limit#
endfunction
soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!