Ok, thanks, but I still can't figure out how to do strafing with it, just turning the camera
. I'm just trying to use it for collision with a single object, so I don't want anything too complicated
.
EDIT: Nevermind, was looking at the wrong functions, still trying to figure out how to do this, but it looks like what is there may work
.
EDIT2: Ok, still having problems, I got strafing, but now I can't turn, and the character box is way too bouncy :S. Any ideas? All I need it to do is collide with one static object.
phy start
autocam off
sync on
sync rate 60
color backdrop 0
position camera 0, 20, -70
make light 1
set directional light 1, -5, -5, 5
temp = make vector3(1) rem this needs to be moved to start of program
make object box 1, 150, 1, 150
phy make rigid body static box 1
remstart
x# = 10
y# = 1
for i = 10 to 20
make object box i, 3, 2, 10
position object i, x#, y#, 0
x# = x# + 3
y# = y# + 1
phy make rigid body static box i
next i
y# = 1
for i = 21 to 31
make object cube i, 2
position object i, -10, y#, 0
y# = y# + 2
phy make rigid body dynamic box i
next i
remend
`make object box 2,3.0,3.0,3.0
`phy make box character controller 2, 0, 6, 0, 1, 2.5, 1, 1, 1.5, 45.0
`hide object 2
Phy_SetupCharacterControllers(1)
Phy_MakeCharacterController(2, 3, 3, 3)
`Create kenimatic object
make object box 100,4.5,5,4.5
phy make rigid body dynamic box 100
phy set rigid body kinematic 100, 1
for i = 1 to 20
if object exist ( i )
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power i, 255
set object ambient i, 0
endif
next i
make camera 2
position camera 2, 0,5,-50
point camera 2, object position x (2), object position y (2), object position z (2)
set camera view 2,400,10,600,210
CH = 2
do
GOSUB moveCharacter
Phy_UpdateCharacterController(2)
` Pusher(2)
point camera 2, object position x (2), object position y (2), object position z (2)
phy update
sync
loop
moveCharacter:
if leftkey ( )
`turn object left CH, 1.0
Phy_MoveCharacterControllerLeft(CH, 10)
endif
if rightkey ( )
`turn object right CH, 1.0
Phy_MoveCharacterControllerRight(CH, 10)
endif
if upkey ( )
Phy_MoveCharacterController(CH, 10)
endif
if downkey()
Phy_MoveCharacterController(CH, -10)
endif
rem camera rotation
Phy_RotateCharacterController(CH, camera angle y() + mousemovex() * 0.3)
`yrotate camera camera angle y() + mousemovex() * 0.3
` xrotate camera camera angle x() + mousemovey() * 0.3
SET CAMERA TO OBJECT ORIENTATION 0,CH
XL# =object position x(CH):YL# =object position Y(CH):ZL# =object position z(CH)
XA# = object angle X(CH):YA# = object angle Y(CH):ZA# = object angle Z(CH)
position camera 0, XL#,YL#,ZL#
` phy set rigid body position 100, object position x(CH), Object position y(CH), object position z(CH)
` phy set rigid body rotation 100, object angle x(CH), Object angle y(CH), object angle z(CH)
RETURN
`Character controller functions
Function Phy_SetupCharacterControllers(MaterialNum)
`Make the material, so it has no bounce
Global CharacterControllerMaterial:CharacterControllerMaterial = MaterialNum
phy Make material CharacterControllerMaterial, "ccmat"
Phy set material restitution CharacterControllerMaterial, 0.0
Phy build material CharacterControllerMaterial
EndFunction
Function Phy_MakeCharacterController(ControllerID, Sizex as float, Sizey as float, Sizez as float)
`First make a rigid body box for the controller
Make object box ControllerID, Sizex, Sizey, Sizez
`Phy make rigid body dynamic box
Phy make rigid body dynamic box ControllerID, CharacterControllerMaterial
EndFunction
Function Phy_MoveCharacterController(ControllerID, Speed as float)
`Move the object forward (along the z axis)
phy add rigid body local force ControllerID, 0, 0, Speed, 4
EndFunction
Function Phy_RotateCharacterController(ControllerID, YAngle as float)
`Rotate the controller along its y axis
Phy set rigid body rotation ControllerID, 0, YAngle, 0
EndFunction
Function Phy_MoveCharacterControllerLeft(ControllerID, Speed as float)
`Apply a negitive force along the x axis
phy add rigid body local force ControllerID, -Speed, 0, 0, 4
EndFunction
Function Phy_MoveCharacterControllerRight(ControllerID, Speed as float)
`Apply a positive force along the x axis
phy add rigid body local force ControllerID, Speed, 0, 0, 4
EndFunction
Function Phy_UpdateCharacterController(ControllerID)
`Make sure the object does not fall over
phy set rigid body rotation ControllerID, 0, Object angle y(ControllerID), 0
`phy set rigid body linear damping ControllerId, 100
`Stop the momentum
phy set rigid body linear momentum ControllerID, 0.0, Phy get rigid body linear momentum y(ControllerID) , 0.0
`phy add rigid body local force ControllerID, 0, -1, 0, 4
EndFunction