BulletSim: fix problem of avatar sliding very slowly occasionally after stopping walking. Consolidate movement tests into the one prestep motion action

user_profiles
Robert Adams 2013-01-20 19:13:18 -08:00
parent 2cb1d5240e
commit 3c4868f613
1 changed files with 41 additions and 34 deletions

View File

@ -56,6 +56,7 @@ public sealed class BSCharacter : BSPhysObject
private int _physicsActorType; private int _physicsActorType;
private bool _isPhysical; private bool _isPhysical;
private bool _flying; private bool _flying;
private bool _wasWalking; // 'true' if the avatar was walking/moving last frame
private bool _setAlwaysRun; private bool _setAlwaysRun;
private bool _throttleUpdates; private bool _throttleUpdates;
private bool _floatOnWater; private bool _floatOnWater;
@ -83,6 +84,7 @@ public sealed class BSCharacter : BSPhysObject
_position = pos; _position = pos;
_flying = isFlying; _flying = isFlying;
_wasWalking = true; // causes first step to initialize standing
_orientation = OMV.Quaternion.Identity; _orientation = OMV.Quaternion.Identity;
_velocity = OMV.Vector3.Zero; _velocity = OMV.Vector3.Zero;
_buoyancy = ComputeBuoyancyFromFlying(isFlying); _buoyancy = ComputeBuoyancyFromFlying(isFlying);
@ -199,8 +201,32 @@ public sealed class BSCharacter : BSPhysObject
// state (flying, colliding, ...). There is code in ODE to do this. // state (flying, colliding, ...). There is code in ODE to do this.
_velocityMotor.Step(timeStep); _velocityMotor.Step(timeStep);
// If we're not supposed to be moving, make sure things are zero.
if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f))
{
if (_wasWalking)
{
_velocityMotor.Zero();
_velocity = OMV.Vector3.Zero;
PhysicsScene.PE.SetLinearVelocity(PhysBody, OMV.Vector3.Zero);
_currentFriction = BSParam.AvatarStandingFriction;
PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
// DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue);
}
_wasWalking = false;
}
else
{
OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue;
if (_currentFriction != BSParam.AvatarFriction)
{
// Probably starting up walking. Set friction to moving friction.
_currentFriction = BSParam.AvatarFriction;
PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
}
// If falling, we keep the world's downward vector no matter what the other axis specify. // If falling, we keep the world's downward vector no matter what the other axis specify.
if (!Flying && !IsColliding) if (!Flying && !IsColliding)
{ {
@ -218,6 +244,8 @@ public sealed class BSCharacter : BSPhysObject
// DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce);
PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce);
_wasWalking = true;
}
}); });
} }
@ -560,27 +588,6 @@ public sealed class BSCharacter : BSPhysObject
PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity");
_velocity = value; _velocity = value;
// Depending on whether the avatar is moving or not, change the friction
// to keep the avatar from slipping around
if (_velocity.Length() == 0)
{
if (_currentFriction != BSParam.AvatarStandingFriction)
{
_currentFriction = BSParam.AvatarStandingFriction;
if (PhysBody.HasPhysicalBody)
PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
}
}
else
{
if (_currentFriction != BSParam.AvatarFriction)
{
_currentFriction = BSParam.AvatarFriction;
if (PhysBody.HasPhysicalBody)
PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
}
}
PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
PhysicsScene.PE.Activate(PhysBody, true); PhysicsScene.PE.Activate(PhysBody, true);
} }
@ -855,7 +862,7 @@ public sealed class BSCharacter : BSPhysObject
_position = entprop.Position; _position = entprop.Position;
_orientation = entprop.Rotation; _orientation = entprop.Rotation;
// Smooth velocity. OpenSimulator is very sensitive to changes in velocity of the avatar // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar
// and will send agent updates to the clients if velocity changes by more than // and will send agent updates to the clients if velocity changes by more than
// 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many
// extra updates. // extra updates.