diff options
author | Robert Adams | 2013-06-20 09:55:40 -0700 |
---|---|---|
committer | Robert Adams | 2013-06-20 09:55:40 -0700 |
commit | bbeff4b8ca34a4567f2215ed5e90637a00d8c81e (patch) | |
tree | 049ba4f566196f67d7bfee97c37256052f8fbc41 /OpenSim/Region/Physics/BulletSPlugin | |
parent | minor: remove mono compiler warnings in WebsocketServerHandler.cs (diff) | |
download | opensim-SC-bbeff4b8ca34a4567f2215ed5e90637a00d8c81e.zip opensim-SC-bbeff4b8ca34a4567f2215ed5e90637a00d8c81e.tar.gz opensim-SC-bbeff4b8ca34a4567f2215ed5e90637a00d8c81e.tar.bz2 opensim-SC-bbeff4b8ca34a4567f2215ed5e90637a00d8c81e.tar.xz |
BulletSim: rework velocity updating when not colliding and not flying
to prevent infinite jumps. Now jumps last only AvatarJumpFrames long
(default 4) which is about as high as in SL.
TODO: jumping should only depend on standing (collision with feet)
rather than collision anywhere on the avatar.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs | 44 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 3 |
2 files changed, 42 insertions, 5 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs index ac8c30c..928b350 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs | |||
@@ -43,8 +43,14 @@ public class BSActorAvatarMove : BSActor | |||
43 | // Set to true if we think we're going up stairs. | 43 | // Set to true if we think we're going up stairs. |
44 | // This state is remembered because collisions will turn on and off as we go up stairs. | 44 | // This state is remembered because collisions will turn on and off as we go up stairs. |
45 | int m_walkingUpStairs; | 45 | int m_walkingUpStairs; |
46 | // The amount the step up is applying. Used to smooth stair walking. | ||
46 | float m_lastStepUp; | 47 | float m_lastStepUp; |
47 | 48 | ||
49 | // Jumping happens over several frames. If use applies up force while colliding, start the | ||
50 | // jump and allow the jump to continue for this number of frames. | ||
51 | int m_jumpFrames = 0; | ||
52 | float m_jumpVelocity = 0f; | ||
53 | |||
48 | public BSActorAvatarMove(BSScene physicsScene, BSPhysObject pObj, string actorName) | 54 | public BSActorAvatarMove(BSScene physicsScene, BSPhysObject pObj, string actorName) |
49 | : base(physicsScene, pObj, actorName) | 55 | : base(physicsScene, pObj, actorName) |
50 | { | 56 | { |
@@ -206,17 +212,45 @@ public class BSActorAvatarMove : BSActor | |||
206 | 212 | ||
207 | if (m_controllingPrim.Friction != BSParam.AvatarFriction) | 213 | if (m_controllingPrim.Friction != BSParam.AvatarFriction) |
208 | { | 214 | { |
209 | // Probably starting up walking. Set friction to moving friction. | 215 | // Probably starting to walk. Set friction to moving friction. |
210 | m_controllingPrim.Friction = BSParam.AvatarFriction; | 216 | m_controllingPrim.Friction = BSParam.AvatarFriction; |
211 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); | 217 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); |
212 | } | 218 | } |
213 | 219 | ||
214 | // If falling, we keep the world's downward vector no matter what the other axis specify. | ||
215 | // The check for RawVelocity.Z < 0 makes jumping work (temporary upward force). | ||
216 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | 220 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) |
217 | { | 221 | { |
218 | if (m_controllingPrim.RawVelocity.Z < 0) | 222 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; |
223 | } | ||
224 | |||
225 | |||
226 | // Colliding and not flying with an upward force. The avatar must be trying to jump. | ||
227 | if (!m_controllingPrim.Flying && m_controllingPrim.IsColliding && stepVelocity.Z > 0) | ||
228 | { | ||
229 | // We allow the upward force to happen for this many frames. | ||
230 | m_jumpFrames = BSParam.AvatarJumpFrames; | ||
231 | m_jumpVelocity = stepVelocity.Z; | ||
232 | } | ||
233 | |||
234 | // The case where the avatar is not colliding and is not flying is special. | ||
235 | // The avatar is either falling or jumping and the user can be applying force to the avatar | ||
236 | // (force in some direction or force up or down). | ||
237 | // If the avatar has negative Z velocity and is not colliding, presume we're falling and keep the velocity. | ||
238 | // If the user is trying to apply upward force but we're not colliding, assume the avatar | ||
239 | // is trying to jump and don't apply the upward force if not touching the ground any more. | ||
240 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | ||
241 | { | ||
242 | // If upward velocity is being applied, this must be a jump and only allow that to go on so long | ||
243 | if (m_jumpFrames > 0) | ||
244 | { | ||
245 | // Since not touching the ground, only apply upward force for so long. | ||
246 | m_jumpFrames--; | ||
247 | stepVelocity.Z = m_jumpVelocity; | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | // Since we're not affected by anything, whatever vertical motion the avatar has, continue that. | ||
219 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | 252 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; |
253 | } | ||
220 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | 254 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); |
221 | } | 255 | } |
222 | 256 | ||
@@ -241,7 +275,7 @@ public class BSActorAvatarMove : BSActor | |||
241 | m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,IsColliding={1},flying={2},targSpeed={3},collisions={4},avHeight={5}", | 275 | m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,IsColliding={1},flying={2},targSpeed={3},collisions={4},avHeight={5}", |
242 | m_controllingPrim.LocalID, m_controllingPrim.IsColliding, m_controllingPrim.Flying, | 276 | m_controllingPrim.LocalID, m_controllingPrim.IsColliding, m_controllingPrim.Flying, |
243 | m_controllingPrim.TargetVelocitySpeed, m_controllingPrim.CollisionsLastTick.Count, m_controllingPrim.Size.Z); | 277 | m_controllingPrim.TargetVelocitySpeed, m_controllingPrim.CollisionsLastTick.Count, m_controllingPrim.Size.Z); |
244 | // This test is done if moving forward, not flying and is colliding with something. | 278 | |
245 | // Check for stairs climbing if colliding, not flying and moving forward | 279 | // Check for stairs climbing if colliding, not flying and moving forward |
246 | if ( m_controllingPrim.IsColliding | 280 | if ( m_controllingPrim.IsColliding |
247 | && !m_controllingPrim.Flying | 281 | && !m_controllingPrim.Flying |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index aad1108..6437b04 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -134,6 +134,7 @@ public static class BSParam | |||
134 | public static float AvatarHeightMidFudge { get; private set; } | 134 | public static float AvatarHeightMidFudge { get; private set; } |
135 | public static float AvatarHeightHighFudge { get; private set; } | 135 | public static float AvatarHeightHighFudge { get; private set; } |
136 | public static float AvatarContactProcessingThreshold { get; private set; } | 136 | public static float AvatarContactProcessingThreshold { get; private set; } |
137 | public static int AvatarJumpFrames { get; private set; } | ||
137 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } | 138 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } |
138 | public static float AvatarStepHeight { get; private set; } | 139 | public static float AvatarStepHeight { get; private set; } |
139 | public static float AvatarStepApproachFactor { get; private set; } | 140 | public static float AvatarStepApproachFactor { get; private set; } |
@@ -567,6 +568,8 @@ public static class BSParam | |||
567 | 0.1f ), | 568 | 0.1f ), |
568 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", | 569 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", |
569 | 1.0f ), | 570 | 1.0f ), |
571 | new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.", | ||
572 | 4 ), | ||
570 | new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction", | 573 | new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction", |
571 | 0.6f ) , | 574 | 0.6f ) , |
572 | new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", | 575 | new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", |