He had a great remake of the character controller that I'm using for my current project.
The code is in the 'Techniques' sticky at the top of this board.
Here's my version of the code...
`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 set material dynamic friction CharacterControllerMaterial, 0.0
phy set material static friction 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 : Hide Object ControllerID
`Phy make rigid body dynamic box
Phy make rigid body dynamic box ControllerID, CharacterControllerMaterial
Phy set rigid body mass ControllerID,100000
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
YRotate Object ControllerID,YAngle
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
That works great. There's no sliding, and it works for WASD movement. My problem is the gravity, linear velocity on the Y, or whatever it is thats causing the problem.
These functions on a terrain are trouble. Whenever I move, after I let go my character controller (actually a rigid dynamic box) goes up in the air a little bit, then comes down. The terrain is bumpy, so it may be that the rigid body is working like a car, and going up in the air after hitting a bump.
The other problem is that randomly after I let go, sometimes it flies up really fast and high into the air, and then gradually comes down. It's like I get hit by an invisible train or something
Does anyone have any idea how to fix this? I've tried setting linear velocity to 0 on the y axis, or -4.8 but it didn't fix.
Thanks.
Sig by BiggAdd.