I was using my home baked character controller at first. It worked, but it had the same weaknesses as it did with the old physics engine. I saw the "Alternate Movement" folder in Demos, so i implemented some of it. CharacterController looked like it would be a great replacement. A little plumbing later, my player and NPC's use the CharacterController through an abstraction in my engine.
Only problem now, player starts with traction, but as soon as a jump is made, or bumps hard into a slanting item that would cause temporary air born, traction is never regained. Even though it comes back to the ground with gravity, and is stable, it never passes the test to say "i have traction".
So here are some peeks at code......
the modified constructor of CharacterControllerInput
Code: Select all
public CharacterControllerInput(Space owningSpace, IGameCamera cameraToUse)
{
CharacterController = new CharacterController();
Space = owningSpace;
Space.Add(CharacterController);
Camera = cameraToUse;
Deactivate();
}
.. so that means, right at construction, the CharacterController is added to the "WORLD". So we shouldn't need to worry about that right?
Now.... creating the instance of the CharacterControllerInput inside a wrapper object.
Code: Select all
movementController = new CharacterControllerInput(Global3dGame.PhysicsWorld, Global3dGame.CamManager.camFirstPerson);
movementController.CharacterController.Body.Mass = Mass;
movementController.CharacterController.JumpSpeed = JumpHeight;
movementController.CharacterController.Body.Height = 10;
movementController.CharacterController.StepManager.MaximumStepHeight = 2;
movementController.CharacterController.StepManager.MinimumDownStepHeight = 1;
movementController.CharacterController.SupportFinder.MaximumSlope = 1;
movementController.CharacterController.TeleportToPosition(_initialPos, 0.001f);
movementController.CharacterController.HorizontalMotionConstraint.Speed = MoveSpeed;
movementController.CharacterController.HorizontalMotionConstraint.MaximumSlidingForce = 0;
movementController.CharacterController.HorizontalMotionConstraint.SlidingSpeed = 0;
movementController.Activate();
the instance creation of the static mesh the player is walking around on...
Code: Select all
TriangleMesh.GetVerticesAndIndicesFromModel(model, out vertices, out indices);
Matrix modelWorld = Matrix.CreateScale(Data.Scale) * Matrix.CreateFromQuaternion(Data.Rotation) * Matrix.CreateTranslation(Data.Position);
for (int i = 0; i < vertices.Length; i++)
vertices[i] = (Matrix.CreateTranslation(vertices[i]) * modelWorld).Translation;
StaticMesh = new StaticMesh(vertices, indices);
StaticMesh.Sidedness = TriangleSidedness.DoubleSided;
StaticMesh.Material.KineticFriction = 1;
StaticMesh.Material.StaticFriction = 1;
Global3dGame.PhysicsWorld.Add(StaticMesh);
Thanks for any time and help. Have a good one.