[SOLVED]CharacterController XBOX Acceleration

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

[SOLVED]CharacterController XBOX Acceleration

Post by Garold »

I would like the character to slowly accelerate. If I move the thumbstick a little I want the character to move a little. Currently the character will move from standing still to maximum speed almost instantly.

In CharacterControllerInput, is this just determining the direction of movement?

Code: Select all

#if XBOX360
                Vector3 forward = Camera.WorldMatrix.Forward;
                forward.Y = 0;
                forward.Normalize();
                Vector3 right = Camera.WorldMatrix.Right;
                totalMovement += gamePadInput.ThumbSticks.Left.Y * new Vector2(forward.X, forward.Z);
                totalMovement += gamePadInput.ThumbSticks.Left.X * new Vector2(right.X, right.Z);
                CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Normalize(totalMovement);
I tried changing the code to this:

Code: Select all

#if XBOX360
                Vector3 forward = Camera.WorldMatrix.Forward;
                forward.Y = 0;
                forward.Normalize();
                Vector3 right = Camera.WorldMatrix.Right;
                totalMovement += gamePadInput.ThumbSticks.Left.Y * gamePadInput.ThumbSticks.Left.Y * new Vector2(forward.X, forward.Z);
                totalMovement += gamePadInput.ThumbSticks.Left.X * gamePadInput.ThumbSticks.Left.X * new Vector2(right.X, right.Z);
                CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Normalize(totalMovement);
However, this did not alter the characters acceleration. Presumably because its just a direction? Also with this change the character could only move right or forward, not left or back, which confused me.

Should I be passing the thumbstick values to HorizontalMotionConstraint and use them to modify MaxSpeed?

I have played with increasing the characters mass. A mass of 30 gives an acceptable smooth stop rather than an abrupt halt. A mass of 300 is more akin to a hovercraft.

Ideally I would like some dampening so that i can accurately move the character small amounts. Also I would like left, right and back speeds to be a lot less than forward speeds.

Any help would be great!

Thank you.
Last edited by Garold on Thu Feb 02, 2012 6:17 pm, edited 1 time in total.
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController XBOX Acceleration

Post by Norbo »

I would like the character to slowly accelerate. If I move the thumbstick a little I want the character to move a little. Currently the character will move from standing still to maximum speed almost instantly.
For the rest of the post, I'll assume this means that holding a stick at 10% will result in the the character accelerating to 10% maximum speed, as opposed to a very slow acceleration all the way up to regular maximum speed. If you want to change acceleration, most of it is the same- just apply changes to the forces rather than the speeds.
However, this did not alter the characters acceleration. Presumably because its just a direction?
Correct.
Should I be passing the thumbstick values to HorizontalMotionConstraint and use them to modify MaxSpeed?
That's one way to do it.
I have played with increasing the characters mass. A mass of 30 gives an acceptable smooth stop rather than an abrupt halt. A mass of 300 is more akin to a hovercraft.
Since mass matters for other interactions, it's better to modify the HorizontalMotionConstraint's MaximumForce, MaximumSlidingForce, and MaximumAirForce if you want to change the acceleration behavior across the board.




The simplest approach to slowing the character would be to set the character.HorizontalMotionConstraint.Speed property directly based on the magnitude of the total movement.

The same thing could be done by making a small modification to the HorizontalMotionConstraint itself so that the MovementDirection isn't just auto-normalized, but instead computes a direction as well as a magnitude (possibly clamped from 0 to 1). The magnitude could multiply the maximum speed in the update. So, if you passed in a movement direction of (.1, .2) corresponding to the controller axis, the character would move much ~80% slower than usual.

However, since you also have other goals:
Also I would like left, right and back speeds to be a lot less than forward speeds.
It would probably be simplest to stick with the external modifications. In addition to the controller axis based speed modification computed above, compute another multiplier based on the movement direction compared against the horizontal camera forward direction. If the dot product between the horizontal camera forward direction and the normalized movement direction is small enough, restrict the Speed to a smaller value. Note that the dot product of two normalized vectors can be used to find the angle using Math.Acos(Vector3.Dot(a, b)); this may help pick a good value.

A discrete cutoff could be used (if more than 75 degrees off horizontal camera forward direction, clamp to half speed), or a smooth cutoff (as the angle approaches 90 degrees, approach half speed), or whatever other behavior you want.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: CharacterController XBOX Acceleration

Post by Garold »

My Xbox controller is perfect. Thank you for such a detailed answer. I multiply the thumbstick value by itself to make it less sensitive a lower speeds.

I cannot thank you enough for your help and for BEPUphysics. Without you I would not be able to complete my game. I would still be writing boring COBOL,VB, SQL, whatever.. somewhere in Manchester or London on a tedious 6 month contract for some bank or insurance company.

If I am lucky and people buy the game I will box you off. :D
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [SOLVED]CharacterController XBOX Acceleration

Post by Norbo »

I cannot thank you enough for your help and for BEPUphysics. Without you I would not be able to complete my game. I would still be writing boring COBOL,VB, SQL, whatever.. somewhere in Manchester or London on a tedious 6 month contract for some bank or insurance company.

If I am lucky and people buy the game I will box you off.
I'm glad to hear it helps :)
Post Reply