Capsule movemet Matrix

Discuss any questions about BEPUphysics or problems encountered.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: Capsule movemet Matrix

Post by alfarza »

I'm given up :cry: , I'm understand what your talking about but I can't convert it to my code (little experience)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Capsule movemet Matrix

Post by Norbo »

If it's an issue of finding the forward/right vectors, it's just a matter of converting the orientation to a matrix, as I mentioned:

Code: Select all

                Matrix orientationMatrix = Matrix.CreateFromQuaternion(playerQuaternion);

                Vector3 forward = orientationMatrix.Forward;
                forward.Y = 0;
                forward.Normalize();
                Vector3 right = orientationMatrix.Right;
                totalMovement += gamePadInput.ThumbSticks.Left.Y * new Vector2(forward.X, forward.Z);
                totalMovement += gamePadInput.ThumbSticks.Left.X * new Vector2(right.X, right.Z);
                CharacterController.MovementDirection = Vector2.Normalize(totalMovement);
Note that in the above, the forward.Y is set to zero and then normalized because the old view matrix used previously could have a pitch component. If you know the playerQuaternion does not contain a pitch component, then you don't need to do the forward.Y = 0 and subsequent normalization.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: Capsule movemet Matrix

Post by alfarza »

and what is "CharacterController.MovementDirection"
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Capsule movemet Matrix

Post by Norbo »

That's just the direction in which the character tries to move.

You don't have to use every bit of that approach. If you just want to add in velocity along a single direction, like along orientationMatrix.Right, then you can just use playerCapsule.LinearVelocity += orientationMatrix.Right * acceleration.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: Capsule movemet Matrix

Post by alfarza »

thanx alot Norbo (finally it works ) :mrgreen:
if any one need to know how it works, here it's:

Matrix orientationMatrix = Matrix.CreateFromQuaternion(playerQuaternion);
Vector3 forward = orientationMatrix.Forward;
forward.Y = 0;
forward.Normalize();
Vector3 right = orientationMatrix.Right;
playerCapsule.LinearVelocity -= orientationMatrix.Forward*padState.ThumbSticks.Left.Y*5;
playerCapsule.LinearVelocity -= orientationMatrix.Right * padState.ThumbSticks.Left.X * 5;
playerCapsule.LinearVelocity += new Vector3(0, -10, 0);
playerCapsule.LinearDamping =0.5f;
playerRotationY -= padState.ThumbSticks.Right.X * MathHelper.ToRadians(2f);
playerQuaternion = Quaternion.CreateFromAxisAngle(Vector3.Up, playerRotationY);
playerPosition = playerCapsule.Position - new Vector3(0, 50, 0);
playerCapsule.Orientation = playerQuaternion;
playerAnimator.World =Matrix.CreateScale(0.5f)*Matrix.CreateFromQuaternion(playerQuaternion) *Matrix.CreateTranslation(playerPosition);

My teacher we will continue in another Discussion (there is many thing I want to know :twisted: )
Post Reply