Gradually rotating a character

Discuss any questions about BEPUphysics or problems encountered.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Gradually rotating a character

Post by Norbo »

Double click on the project's properties, go to the Build tab, and in the General category, there's a text field labelled "Conditional compilation symbols". Put CHECKMATH in there. Use a semicolon to separate multiple symbols. Recompile the project and all the areas that check for CHECKMATH will now be compiled and ready.
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: Gradually rotating a character

Post by Peter Prins »

I believe I may have just solved the issue. When the object gets deactivated the gravity impulses still accumulate. When it is reactivated because the player walks into it the box has a huge velocity and shoots through the floor.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Gradually rotating a character

Post by Norbo »

That's interesting; I assume ApplyLinearImpulse was being used externally without a check for inactivity? (Other external methods of modifying velocities, like ApplyImpulse or the velocity/momentum properties, force the entity awake. ApplyLinear/AngularImpulse are raw changes to the entity's state without any protective checks for performance reasons.)
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: Gradually rotating a character

Post by Peter Prins »

Yes, That's the one I used. I specifically Didn't want the objects to be activated by the constant gravity. I didn't realize the impulses would accumulate as they did. I've added a check for activity to the method that applies the gravity.
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: Gradually rotating a character

Post by Peter Prins »

All right, I'm finally getting back to this. I've implemented a spherical body for the character to walk around on, with gravity pointing towards its centre. Every game step I rotate the character to match the local up direction, by simply changing the Orientation. (I might move this to every physics step at some point, but since the character rotates so gradually it doesn't seem to be an issue.) The problem I'm currently trying to solve is getting the walking directions correct. At the moment the closer I get to the 'equator' the more the walking directions start to align with that equator (both of them). I assume the change has to be made in the Horizontal Motion constraint. But I'm having a hard time grasping the way it works. Could you point me in the right direction?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Gradually rotating a character

Post by Norbo »

There's a few different spots that need to be changed for a nonstandard down character:
1) CharacterController.ExpandBoundingBox must be changed to allow arbitrary down directions.
2) In HorizontalMotionConstraint.Update, the chunk of code that runs when MovementMode != MovementMode.Floating and isTryingToMove = true needs to be changed so that lineStart is the movement direction in 3d.
3) The movement direction must also be transformed into 3d when the character is floating.

The transformation to 3d for #2 and #3 can be done in a few ways; in one of my implementations, I changed the 2d movement direction to be in terms of the view direction. In other words, movementDirection.Y corresponded to movement along the view direction projected onto the character's horizontal plane. Then, movementDirection.X corresponded to movement along the 'strafe' direction, which was found by taking the cross product of the character's down direction and the horizontal view direction.

So, to get the 3d movementDirection, this transform was applied:

Code: Select all

        internal void GetMovementDirectionIn3D(out Vector3 movement3d)
        {
            movement3d = character.horizontalViewDirection * movementDirection.Y + character.StrafeDirection * movementDirection.X;
        }
For the floating case, you have to define both jacobian entries. One of the jacobians is just the motion direction, the other is a direction 90 degrees off. So this would work:

Code: Select all

                GetMovementDirectionIn3D(out linearJacobianA1);
                Vector3.Cross(ref linearJacobianA1, ref character.down, out linearJacobianA2);
I might be forgetting something, but I believe these were the main areas that have to be updated.
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: Gradually rotating a character

Post by Peter Prins »

Awesome, that wasn't too hard. :D Thanks for the help, I'll let you know if I notice any more strange behavior.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Gradually rotating a character

Post by Garold »

You can right click your project name in the solution explorer. Then left click "properties". This will display the properties window for said project. Alternatively, you can type Alt + Enter.

Then you can add "CHECKMATH" to the conditional compilation symbols textbox. Use a semi-colon as a separator.

I think that's right, please correct me if I am wrong.
BEPUphysics rules my world
http://cloneofduty.com
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Gradually rotating a character

Post by Garold »

Sorry! You already have the answer, I didn't see page 2, doh!
BEPUphysics rules my world
http://cloneofduty.com
Post Reply