CharacterController sliding on start/stop
Posted: Thu Jul 13, 2017 3:04 pm
Hello Norbo and thanks for the awesome library!
I'm using a CharacterController and i'm moving it using the MovementDirection of the HorizontalMotionConstraint property as displayed in the user input handler snippet bellow.
What i'm experiencing is that my character "slides" like he is accelerating/decelerating when he starts/stops moving and nothing that i do changes this..
Is this a normal and expected behavior? If it is not, can you check my configuration below please?
I have tried several things to counteract this (mainly by searching the forums) and i'm posting them below..
The space and character controller initialization scripts are:
Character Controller initializer:
The CharacterHeight in question is set to 1.75f and the Width to 0.75f
User Input handler:
I tried doing the following when the entity is not moving: (not all simultaneously)
I have even tried modifying it to be a Kinematic object when it stops moving and re-enabling it to dynamic(providing it's previous mass and local inertia tensor) but to no effect..
In the debugger, i see that the object has a traction support (it's not floating)
I'm losing my sanity so any idea is much appreciated..
I'm using a CharacterController and i'm moving it using the MovementDirection of the HorizontalMotionConstraint property as displayed in the user input handler snippet bellow.
What i'm experiencing is that my character "slides" like he is accelerating/decelerating when he starts/stops moving and nothing that i do changes this..
Is this a normal and expected behavior? If it is not, can you check my configuration below please?
I have tried several things to counteract this (mainly by searching the forums) and i'm posting them below..
The space and character controller initialization scripts are:
Code: Select all
Space.ForceUpdater.Gravity = new Vector3(0, -10f, 0);
Space.TimeStepSettings.TimeStepDuration = 1f / 60f;
Code: Select all
var cc = new CharacterController(
new Vector3(PlayerSpawnPoint.Center.X, PlayerSpawnPoint.Center.Y, PlayerSpawnPoint.Center.Z), //position
CharacterHeight, //height
CharacterHeight / 2f, //crouching height
CharacterHeight / 4f, //prone height
CharacterWidth,//radius
0.1f, //margin
10);//mass
cc.Body.CollisionInformation.CollisionRules.Group = characters;
Space.Add(cc);
User Input handler:
Code: Select all
Moving = false;
Direction = MoveDirection.None;
CharacterController.Body.Orientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)-Math.PI * (_playerMovement.Heading * 0.0055f) / 100f);
Vector3 forwardDir = CharacterController.Body.WorldTransform.Forward;
Vector3 upDir = CharacterController.Body.WorldTransform.Up;
Vector3 strafeDir = CharacterController.Body.WorldTransform.Right;
forwardDir.Normalize();
upDir.Normalize();
strafeDir.Normalize();
WalkDirection = new Vector3(0, 0, 0);
if (_playerMovement.RightDirection < 0)
{
WalkDirection -= strafeDir;
Direction |= MoveDirection.Left;
Moving = true;
}
if (_playerMovement.RightDirection > 0)
{
WalkDirection += strafeDir;
Direction |= MoveDirection.Right;
Moving = true;
}
if (_playerMovement.ForwardDirection < 0)
{
WalkDirection -= forwardDir;
Direction |= MoveDirection.Backward;
Moving = true;
}
if (_playerMovement.ForwardDirection > 0)
{
WalkDirection += forwardDir;
Direction |= MoveDirection.Forward;
Moving = true;
}
WalkDirection.Normalize();
Vector3 refVector = WalkDirection * _moveSpeed; //_moveSpeed is 10f in this example
CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Normalize(new Vector2(refVector.X, refVector.Z));
Code: Select all
CharacterController.Body.LinearMomentum = Vector3.Zero;
CharacterController.Body.AngularMomentum = Vector3.Zero;
CharacterController.HorizontalMotionConstraint.MovementDirection = new Vector2(0, 0);
CharacterController.Body.AngularVelocity = Vector3.Zero;
CharacterController.HorizontalMotionConstraint.MaximumForce=float.Max;
CharacterController.HorizontalMotionConstraint.MaximumAccelerationForce=float.Max;
In the debugger, i see that the object has a traction support (it's not floating)
I'm losing my sanity so any idea is much appreciated..