CharacterController doesn't find traction after losing it

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
GiveUpGames
Posts: 9
Joined: Thu Jul 25, 2013 11:20 pm

CharacterController doesn't find traction after losing it

Post by GiveUpGames »

i've integrated BEPU into my game engine. So far, it's awesome. Good job.

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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController doesn't find traction after losing i

Post by Norbo »

I am unable to replicate the specific failure of not regaining traction, but here are two notes:

Code: Select all

            movementController.CharacterController.Body.Height = 10;
Directly modifying the body height won't stick when the character changes stances. Instead, set the CharacterController.StanceManager.StandingHeight/CrouchingHeight.

Code: Select all

            movementController.CharacterController.TeleportToPosition(_initialPos, 0.001f);
The TeleportToPosition function is designed to be used when 1) contacts are expected to exist, and 2) pre-existing contacts are expected to be an issue. These conditions are rare outside of the internal usage of the character, which is why the function is private (or at least, it is in the latest version). For more common usage, simply teleporting the character body entity directly by setting its Position property would be sufficient.

As for the traction issue, is this using the latest version? If it is, could you modify a demo within the BEPUphysicsDemos for me to run and debug? If it's not the latest version, the latest version may contain a fix.
GiveUpGames
Posts: 9
Joined: Thu Jul 25, 2013 11:20 pm

Re: CharacterController doesn't find traction after losing i

Post by GiveUpGames »

Thx for response.

I'll try both code changes. A little more info....


Height
Good advice on the height thing. Kinda-related question : Can stance change without me (player or developer) explicitly setting it? I notice if i bump into a wall, i seem to "drop down" by about half the height. In fact, the symptom of losing traction and dropping down seem to go hand in hand. The reason i adjusted height was related to some answers i saw else where on this forum , about the RAY possibly getting caught in a bad place, and i saw that internally, the height was used to calculate the ray.


Version
As far as latest version, this might be the kicker. I'm using the latest XNA version. I get the impression that branch is the red-headed step-child, the same way XNA is for Microsoft (trust me, i understand).

Some tell-tale signs of the version disparity:
I had to manually change Matrix2X2 -> Matrix2x2 (lower case 'x')

Originally, i had the latest XNA, BUT then i grabbed the latest "demo" from the dependency free branch, and that caused lots of errors of course. Eventually i found the whole package under the XNA branch.


Debugging
Stepping through the code of the SupportManager, i see that once it loses traction, there is ONE frame where it tries lots of other things, but that's it. After 2 frames "HasTraction" and "hadTraction" are both false, then it fails the initial test, then no more tests are done.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController doesn't find traction after losing i

Post by Norbo »

Can stance change without me (player or developer) explicitly setting it? I notice if i bump into a wall, i seem to "drop down" by about half the height. In fact, the symptom of losing traction and dropping down seem to go hand in hand.
There is only one case where the stance can change that isn't immediate response to input: if the character is crouching and the character wants to stand (i.e. the player has let go of the crouch button) but there is something stopping the character from standing, the character won't try to stand. However, as soon as the character's full height is unoccluded, the character will stand. This goes along with the concept of a 'desired' stance: rather than directly specifying what stance the character is in, there is a goal state which is met only if possible.
The reason i adjusted height was related to some answers i saw else where on this forum , about the RAY possibly getting caught in a bad place, and i saw that internally, the height was used to calculate the ray.
Those posts were probably referring to the SimpleCharacterController. It floats on a ray which can indeed get into a bad situation.

The full CharacterController, however, finds support based on the contacts with the body and some other queries. It is not vulnerable to the failures of the SimpleCharacterController.
I'm using the latest XNA version. I get the impression that branch is the red-headed step-child, the same way XNA is for Microsoft (trust me, i understand).
The main branch was the XNA branch up until a few weeks ago; it should have all of the relevant changes.
After 2 frames "HasTraction" and "hadTraction" are both false, then it fails the initial test, then no more tests are done.
That's strange; if the body is sitting on something, there are contacts, and the first test should find them to use as supports. I'll probably need a runnable/debuggable demo in the BEPUphysicsDemos showing the issue to be of much help with the details.
GiveUpGames
Posts: 9
Joined: Thu Jul 25, 2013 11:20 pm

Re: CharacterController doesn't find traction after losing i

Post by GiveUpGames »

Ok. Fair enough. I might have failed to port something properly out of the demo.

The more i play with it, the more i'm starting to think that the character is simply falling through the geometry when it collides with "curbs" in the street (going up to a sidewalk).


Before now, i was manipulating a sphere for my character. That had no problems. Is it possible that the hard edges of the Cylinder will break through geometry under certain conditions? Is it possible there is some 'allowedPenetration' setting that's set too high? Any other reasons why entities would fall through a complicated staticMesh? I couldn't find any allowedPenetration setting on the Space or it's members.

Thanks for the responses.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController doesn't find traction after losing i

Post by Norbo »

Is it possible that the hard edges of the Cylinder will break through geometry under certain conditions? Is it possible there is some 'allowedPenetration' setting that's set too high? Any other reasons why entities would fall through a complicated staticMesh? I couldn't find any allowedPenetration setting on the Space or it's members.
I would not expect the cylinder's shape to be an issue. While there exists an "AllowedPenetration" tuning factor, it should also not be an issue unless your objects are very small (say, less than 0.05 units; CollisionDetectionSettings.AllowedPenetration defaults to 0.01). Even then, things wouldn't usually fall through; they would just stay penetrated, up to the allowed penetration. Further, even if it did stay penetrated, a support would still be detected.
Post Reply