aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRobert Adams2013-01-20 19:13:18 -0800
committerRobert Adams2013-01-20 23:09:54 -0800
commit3c4868f61362c2c86cef9f98e197362f57ca627b (patch)
treeba84b0682602c9c1c4c729f51c32e9bd7d64c0ff
parentBulletSim: small fix making sure terrain height is calculated (diff)
downloadopensim-SC_OLD-3c4868f61362c2c86cef9f98e197362f57ca627b.zip
opensim-SC_OLD-3c4868f61362c2c86cef9f98e197362f57ca627b.tar.gz
opensim-SC_OLD-3c4868f61362c2c86cef9f98e197362f57ca627b.tar.bz2
opensim-SC_OLD-3c4868f61362c2c86cef9f98e197362f57ca627b.tar.xz
BulletSim: fix problem of avatar sliding very slowly occasionally after stopping walking. Consolidate movement tests into the one prestep motion action
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs75
1 files changed, 41 insertions, 34 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 696c4bd..cd279e3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -56,6 +56,7 @@ public sealed class BSCharacter : BSPhysObject
56 private int _physicsActorType; 56 private int _physicsActorType;
57 private bool _isPhysical; 57 private bool _isPhysical;
58 private bool _flying; 58 private bool _flying;
59 private bool _wasWalking; // 'true' if the avatar was walking/moving last frame
59 private bool _setAlwaysRun; 60 private bool _setAlwaysRun;
60 private bool _throttleUpdates; 61 private bool _throttleUpdates;
61 private bool _floatOnWater; 62 private bool _floatOnWater;
@@ -83,6 +84,7 @@ public sealed class BSCharacter : BSPhysObject
83 _position = pos; 84 _position = pos;
84 85
85 _flying = isFlying; 86 _flying = isFlying;
87 _wasWalking = true; // causes first step to initialize standing
86 _orientation = OMV.Quaternion.Identity; 88 _orientation = OMV.Quaternion.Identity;
87 _velocity = OMV.Vector3.Zero; 89 _velocity = OMV.Vector3.Zero;
88 _buoyancy = ComputeBuoyancyFromFlying(isFlying); 90 _buoyancy = ComputeBuoyancyFromFlying(isFlying);
@@ -199,25 +201,51 @@ public sealed class BSCharacter : BSPhysObject
199 // state (flying, colliding, ...). There is code in ODE to do this. 201 // state (flying, colliding, ...). There is code in ODE to do this.
200 202
201 _velocityMotor.Step(timeStep); 203 _velocityMotor.Step(timeStep);
202 OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue;
203 204
204 // If falling, we keep the world's downward vector no matter what the other axis specify. 205 // If we're not supposed to be moving, make sure things are zero.
205 if (!Flying && !IsColliding) 206 if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f))
206 { 207 {
207 stepVelocity.Z = _velocity.Z; 208 if (_wasWalking)
208 // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); 209 {
210 _velocityMotor.Zero();
211 _velocity = OMV.Vector3.Zero;
212 PhysicsScene.PE.SetLinearVelocity(PhysBody, OMV.Vector3.Zero);
213 _currentFriction = BSParam.AvatarStandingFriction;
214 PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
215 // DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue);
216 }
217 _wasWalking = false;
209 } 218 }
219 else
220 {
221 OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue;
222
223 if (_currentFriction != BSParam.AvatarFriction)
224 {
225 // Probably starting up walking. Set friction to moving friction.
226 _currentFriction = BSParam.AvatarFriction;
227 PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
228 }
210 229
211 // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. 230 // If falling, we keep the world's downward vector no matter what the other axis specify.
212 OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass; 231 if (!Flying && !IsColliding)
232 {
233 stepVelocity.Z = _velocity.Z;
234 // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
235 }
236
237 // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force.
238 OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass;
213 239
214 // Should we check for move force being small and forcing velocity to zero? 240 // Should we check for move force being small and forcing velocity to zero?
215 241
216 // Add special movement force to allow avatars to walk up stepped surfaces. 242 // Add special movement force to allow avatars to walk up stepped surfaces.
217 moveForce += WalkUpStairs(); 243 moveForce += WalkUpStairs();
218 244
219 // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); 245 // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce);
220 PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); 246 PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce);
247 _wasWalking = true;
248 }
221 }); 249 });
222 } 250 }
223 251
@@ -560,27 +588,6 @@ public sealed class BSCharacter : BSPhysObject
560 PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); 588 PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity");
561 589
562 _velocity = value; 590 _velocity = value;
563 // Depending on whether the avatar is moving or not, change the friction
564 // to keep the avatar from slipping around
565 if (_velocity.Length() == 0)
566 {
567 if (_currentFriction != BSParam.AvatarStandingFriction)
568 {
569 _currentFriction = BSParam.AvatarStandingFriction;
570 if (PhysBody.HasPhysicalBody)
571 PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
572 }
573 }
574 else
575 {
576 if (_currentFriction != BSParam.AvatarFriction)
577 {
578 _currentFriction = BSParam.AvatarFriction;
579 if (PhysBody.HasPhysicalBody)
580 PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
581 }
582 }
583
584 PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); 591 PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
585 PhysicsScene.PE.Activate(PhysBody, true); 592 PhysicsScene.PE.Activate(PhysBody, true);
586 } 593 }
@@ -855,7 +862,7 @@ public sealed class BSCharacter : BSPhysObject
855 _position = entprop.Position; 862 _position = entprop.Position;
856 _orientation = entprop.Rotation; 863 _orientation = entprop.Rotation;
857 864
858 // Smooth velocity. OpenSimulator is very sensitive to changes in velocity of the avatar 865 // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar
859 // and will send agent updates to the clients if velocity changes by more than 866 // and will send agent updates to the clients if velocity changes by more than
860 // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many 867 // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many
861 // extra updates. 868 // extra updates.