diff options
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs')
-rwxr-xr-x | OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs | 97 |
1 files changed, 40 insertions, 57 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs index 12ffacb..79ee00f 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs | |||
@@ -47,10 +47,9 @@ public class BSActorAvatarMove : BSActor | |||
47 | // The amount the step up is applying. Used to smooth stair walking. | 47 | // The amount the step up is applying. Used to smooth stair walking. |
48 | float m_lastStepUp; | 48 | float m_lastStepUp; |
49 | 49 | ||
50 | // Jumping happens over several frames. If use applies up force while colliding, start the | 50 | // There are times the velocity is set but we don't want to inforce stationary until the |
51 | // jump and allow the jump to continue for this number of frames. | 51 | // real velocity drops. |
52 | int m_jumpFrames = 0; | 52 | bool m_waitingForLowVelocityForStationary = false; |
53 | float m_jumpVelocity = 0f; | ||
54 | 53 | ||
55 | public BSActorAvatarMove(BSScene physicsScene, BSPhysObject pObj, string actorName) | 54 | public BSActorAvatarMove(BSScene physicsScene, BSPhysObject pObj, string actorName) |
56 | : base(physicsScene, pObj, actorName) | 55 | : base(physicsScene, pObj, actorName) |
@@ -117,11 +116,19 @@ public class BSActorAvatarMove : BSActor | |||
117 | m_velocityMotor.SetTarget(targ); | 116 | m_velocityMotor.SetTarget(targ); |
118 | m_velocityMotor.SetCurrent(vel); | 117 | m_velocityMotor.SetCurrent(vel); |
119 | m_velocityMotor.Enabled = true; | 118 | m_velocityMotor.Enabled = true; |
119 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,SetVelocityAndTarget,vel={1}, targ={2}", | ||
120 | m_controllingPrim.LocalID, vel, targ); | ||
121 | m_waitingForLowVelocityForStationary = false; | ||
120 | } | 122 | } |
121 | }); | 123 | }); |
122 | } | 124 | } |
123 | 125 | ||
124 | // If a hover motor has not been created, create one and start the hovering. | 126 | public void SuppressStationayCheckUntilLowVelocity() |
127 | { | ||
128 | m_waitingForLowVelocityForStationary = true; | ||
129 | } | ||
130 | |||
131 | // If a movement motor has not been created, create one and start the hovering. | ||
125 | private void ActivateAvatarMove() | 132 | private void ActivateAvatarMove() |
126 | { | 133 | { |
127 | if (m_velocityMotor == null) | 134 | if (m_velocityMotor == null) |
@@ -133,13 +140,14 @@ public class BSActorAvatarMove : BSActor | |||
133 | 1f // efficiency | 140 | 1f // efficiency |
134 | ); | 141 | ); |
135 | m_velocityMotor.ErrorZeroThreshold = BSParam.AvatarStopZeroThreshold; | 142 | m_velocityMotor.ErrorZeroThreshold = BSParam.AvatarStopZeroThreshold; |
136 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | 143 | // m_velocityMotor.PhysicsScene = m_controllingPrim.PhysScene; // DEBUG DEBUG so motor will output detail log messages. |
137 | SetVelocityAndTarget(m_controllingPrim.RawVelocity, m_controllingPrim.TargetVelocity, true /* inTaintTime */); | 144 | SetVelocityAndTarget(m_controllingPrim.RawVelocity, m_controllingPrim.TargetVelocity, true /* inTaintTime */); |
138 | 145 | ||
139 | m_physicsScene.BeforeStep += Mover; | 146 | m_physicsScene.BeforeStep += Mover; |
140 | m_controllingPrim.OnPreUpdateProperty += Process_OnPreUpdateProperty; | 147 | m_controllingPrim.OnPreUpdateProperty += Process_OnPreUpdateProperty; |
141 | 148 | ||
142 | m_walkingUpStairs = 0; | 149 | m_walkingUpStairs = 0; |
150 | m_waitingForLowVelocityForStationary = false; | ||
143 | } | 151 | } |
144 | } | 152 | } |
145 | 153 | ||
@@ -190,12 +198,15 @@ public class BSActorAvatarMove : BSActor | |||
190 | // if colliding with something stationary and we're not doing volume detect . | 198 | // if colliding with something stationary and we're not doing volume detect . |
191 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) | 199 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) |
192 | { | 200 | { |
193 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,totalForce={1}, vel={2}", /* DEBUG */ | 201 | if (m_waitingForLowVelocityForStationary) |
194 | m_controllingPrim.LocalID, m_physicsScene.PE.GetTotalForce(m_controllingPrim.PhysBody), m_controllingPrim.Velocity); /* DEBUG */ | 202 | { |
195 | // If velocity is very small, assume it is movement creep and suppress it. | 203 | // if waiting for velocity to drop and it has finally dropped, we can be stationary |
196 | // Applying push forces (Character.AddForce) should move the avatar and that is only seen here as velocity. | 204 | if (m_controllingPrim.RawVelocity.LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) |
197 | if ( (m_controllingPrim.Velocity.LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) | 205 | { |
198 | && (m_physicsScene.PE.GetTotalForce(m_controllingPrim.PhysBody).LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) ) | 206 | m_waitingForLowVelocityForStationary = false; |
207 | } | ||
208 | } | ||
209 | if (!m_waitingForLowVelocityForStationary) | ||
199 | { | 210 | { |
200 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); | 211 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); |
201 | m_controllingPrim.IsStationary = true; | 212 | m_controllingPrim.IsStationary = true; |
@@ -203,8 +214,8 @@ public class BSActorAvatarMove : BSActor | |||
203 | } | 214 | } |
204 | else | 215 | else |
205 | { | 216 | { |
206 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,not zeroing because velocity={1}", | 217 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,waitingForLowVel,rawvel={1}", |
207 | m_controllingPrim.LocalID, m_controllingPrim.Velocity); | 218 | m_controllingPrim.LocalID, m_controllingPrim.RawVelocity.Length()); |
208 | } | 219 | } |
209 | } | 220 | } |
210 | 221 | ||
@@ -250,50 +261,24 @@ public class BSActorAvatarMove : BSActor | |||
250 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); | 261 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); |
251 | } | 262 | } |
252 | 263 | ||
253 | // If not flying and not colliding, assume falling and keep the downward motion component. | 264 | // 'm_velocityMotor is used for walking, flying, and jumping and will thus have the correct values |
254 | // This check is done here for the next jump test. | 265 | // for Z. But in come cases it must be over-ridden. Like when falling or jumping. |
255 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | ||
256 | { | ||
257 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | ||
258 | } | ||
259 | 266 | ||
260 | // Colliding and not flying with an upward force. The avatar must be trying to jump. | 267 | float realVelocityZ = m_controllingPrim.RawVelocity.Z; |
261 | if (!m_controllingPrim.Flying && m_controllingPrim.IsColliding && stepVelocity.Z > 0) | ||
262 | { | ||
263 | // We allow the upward force to happen for this many frames. | ||
264 | m_jumpFrames = BSParam.AvatarJumpFrames; | ||
265 | m_jumpVelocity = stepVelocity.Z; | ||
266 | } | ||
267 | 268 | ||
268 | // The case where the avatar is not colliding and is not flying is special. | 269 | // If not flying and falling, we over-ride the stepping motor so we can fall to the ground |
269 | // The avatar is either falling or jumping and the user can be applying force to the avatar | 270 | if (!m_controllingPrim.Flying && realVelocityZ < 0) |
270 | // (force in some direction or force up or down). | ||
271 | // If the avatar has negative Z velocity and is not colliding, presume we're falling and keep the velocity. | ||
272 | // If the user is trying to apply upward force but we're not colliding, assume the avatar | ||
273 | // is trying to jump and don't apply the upward force if not touching the ground any more. | ||
274 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | ||
275 | { | 271 | { |
276 | // If upward velocity is being applied, this must be a jump and only allow that to go on so long | 272 | // Can't fall faster than this |
277 | if (m_jumpFrames > 0) | 273 | if (realVelocityZ < BSParam.AvatarTerminalVelocity) |
278 | { | 274 | { |
279 | // Since not touching the ground, only apply upward force for so long. | 275 | realVelocityZ = BSParam.AvatarTerminalVelocity; |
280 | m_jumpFrames--; | ||
281 | stepVelocity.Z = m_jumpVelocity; | ||
282 | } | 276 | } |
283 | else | 277 | |
284 | { | 278 | stepVelocity.Z = realVelocityZ; |
285 | // Since we're not affected by anything, the avatar must be falling and we do not want that to be too fast. | ||
286 | if (m_controllingPrim.RawVelocity.Z < BSParam.AvatarTerminalVelocity) | ||
287 | { | ||
288 | stepVelocity.Z = BSParam.AvatarTerminalVelocity; | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | ||
293 | } | ||
294 | } | ||
295 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
296 | } | 279 | } |
280 | // m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,DEBUG,motorCurrent={1},realZ={2},flying={3},collid={4},jFrames={5}", | ||
281 | // m_controllingPrim.LocalID, m_velocityMotor.CurrentValue, realVelocityZ, m_controllingPrim.Flying, m_controllingPrim.IsColliding, m_jumpFrames); | ||
297 | 282 | ||
298 | //Alicia: Maintain minimum height when flying. | 283 | //Alicia: Maintain minimum height when flying. |
299 | // SL has a flying effect that keeps the avatar flying above the ground by some margin | 284 | // SL has a flying effect that keeps the avatar flying above the ground by some margin |
@@ -304,6 +289,8 @@ public class BSActorAvatarMove : BSActor | |||
304 | 289 | ||
305 | if( m_controllingPrim.Position.Z < hover_height) | 290 | if( m_controllingPrim.Position.Z < hover_height) |
306 | { | 291 | { |
292 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,addingUpforceForGroundMargin,height={1},hoverHeight={2}", | ||
293 | m_controllingPrim.LocalID, m_controllingPrim.Position.Z, hover_height); | ||
307 | stepVelocity.Z += BSParam.AvatarFlyingGroundUpForce; | 294 | stepVelocity.Z += BSParam.AvatarFlyingGroundUpForce; |
308 | } | 295 | } |
309 | } | 296 | } |
@@ -328,11 +315,7 @@ public class BSActorAvatarMove : BSActor | |||
328 | if (m_controllingPrim.IsStationary) | 315 | if (m_controllingPrim.IsStationary) |
329 | { | 316 | { |
330 | entprop.Position = m_controllingPrim.RawPosition; | 317 | entprop.Position = m_controllingPrim.RawPosition; |
331 | // Suppress small movement velocity | 318 | entprop.Velocity = OMV.Vector3.Zero; |
332 | if (entprop.Velocity.LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) { | ||
333 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,OnPreUpdate,zeroing velocity={1}", m_controllingPrim.LocalID, entprop.Velocity); | ||
334 | entprop.Velocity = OMV.Vector3.Zero; | ||
335 | } | ||
336 | m_physicsScene.PE.SetTranslation(m_controllingPrim.PhysBody, entprop.Position, entprop.Rotation); | 319 | m_physicsScene.PE.SetTranslation(m_controllingPrim.PhysBody, entprop.Position, entprop.Rotation); |
337 | } | 320 | } |
338 | 321 | ||