diff options
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs')
-rw-r--r-- | OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs | 106 |
1 files changed, 51 insertions, 55 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs index 0191893..40c6b98 100644 --- 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) |
@@ -109,19 +108,23 @@ public class BSActorAvatarMove : BSActor | |||
109 | { | 108 | { |
110 | if (m_velocityMotor != null) | 109 | if (m_velocityMotor != null) |
111 | { | 110 | { |
112 | // if (targ == OMV.Vector3.Zero) | ||
113 | // Util.PrintCallStack(); | ||
114 | // | ||
115 | // Console.WriteLine("SetVelocityAndTarget, {0} {1}", vel, targ); | ||
116 | m_velocityMotor.Reset(); | 111 | m_velocityMotor.Reset(); |
117 | m_velocityMotor.SetTarget(targ); | 112 | m_velocityMotor.SetTarget(targ); |
118 | m_velocityMotor.SetCurrent(vel); | 113 | m_velocityMotor.SetCurrent(vel); |
119 | m_velocityMotor.Enabled = true; | 114 | m_velocityMotor.Enabled = true; |
115 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,SetVelocityAndTarget,vel={1}, targ={2}", | ||
116 | m_controllingPrim.LocalID, vel, targ); | ||
117 | m_waitingForLowVelocityForStationary = false; | ||
120 | } | 118 | } |
121 | }); | 119 | }); |
122 | } | 120 | } |
123 | 121 | ||
124 | // If a hover motor has not been created, create one and start the hovering. | 122 | public void SuppressStationayCheckUntilLowVelocity() |
123 | { | ||
124 | m_waitingForLowVelocityForStationary = true; | ||
125 | } | ||
126 | |||
127 | // If a movement motor has not been created, create one and start the movement | ||
125 | private void ActivateAvatarMove() | 128 | private void ActivateAvatarMove() |
126 | { | 129 | { |
127 | if (m_velocityMotor == null) | 130 | if (m_velocityMotor == null) |
@@ -133,13 +136,14 @@ public class BSActorAvatarMove : BSActor | |||
133 | 1f // efficiency | 136 | 1f // efficiency |
134 | ); | 137 | ); |
135 | m_velocityMotor.ErrorZeroThreshold = BSParam.AvatarStopZeroThreshold; | 138 | m_velocityMotor.ErrorZeroThreshold = BSParam.AvatarStopZeroThreshold; |
136 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | 139 | // 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 */); | 140 | SetVelocityAndTarget(m_controllingPrim.RawVelocity, m_controllingPrim.TargetVelocity, true /* inTaintTime */); |
138 | 141 | ||
139 | m_physicsScene.BeforeStep += Mover; | 142 | m_physicsScene.BeforeStep += Mover; |
140 | m_controllingPrim.OnPreUpdateProperty += Process_OnPreUpdateProperty; | 143 | m_controllingPrim.OnPreUpdateProperty += Process_OnPreUpdateProperty; |
141 | 144 | ||
142 | m_walkingUpStairs = 0; | 145 | m_walkingUpStairs = 0; |
146 | m_waitingForLowVelocityForStationary = false; | ||
143 | } | 147 | } |
144 | } | 148 | } |
145 | 149 | ||
@@ -153,7 +157,7 @@ public class BSActorAvatarMove : BSActor | |||
153 | } | 157 | } |
154 | } | 158 | } |
155 | 159 | ||
156 | // Called just before the simulation step. Update the vertical position for hoverness. | 160 | // Called just before the simulation step. |
157 | private void Mover(float timeStep) | 161 | private void Mover(float timeStep) |
158 | { | 162 | { |
159 | // Don't do movement while the object is selected. | 163 | // Don't do movement while the object is selected. |
@@ -187,12 +191,28 @@ public class BSActorAvatarMove : BSActor | |||
187 | 191 | ||
188 | if (m_controllingPrim.IsColliding) | 192 | if (m_controllingPrim.IsColliding) |
189 | { | 193 | { |
190 | // If we are colliding with a stationary object, presume we're standing and don't move around | 194 | // if colliding with something stationary and we're not doing volume detect . |
191 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) | 195 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) |
192 | { | 196 | { |
193 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); | 197 | if (m_waitingForLowVelocityForStationary) |
194 | m_controllingPrim.IsStationary = true; | 198 | { |
195 | m_controllingPrim.ZeroMotion(true /* inTaintTime */); | 199 | // if waiting for velocity to drop and it has finally dropped, we can be stationary |
200 | if (m_controllingPrim.RawVelocity.LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) | ||
201 | { | ||
202 | m_waitingForLowVelocityForStationary = false; | ||
203 | } | ||
204 | } | ||
205 | if (!m_waitingForLowVelocityForStationary) | ||
206 | { | ||
207 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); | ||
208 | m_controllingPrim.IsStationary = true; | ||
209 | m_controllingPrim.ZeroMotion(true /* inTaintTime */); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,waitingForLowVel,rawvel={1}", | ||
214 | m_controllingPrim.LocalID, m_controllingPrim.RawVelocity.Length()); | ||
215 | } | ||
196 | } | 216 | } |
197 | 217 | ||
198 | // Standing has more friction on the ground | 218 | // Standing has more friction on the ground |
@@ -222,8 +242,8 @@ public class BSActorAvatarMove : BSActor | |||
222 | } | 242 | } |
223 | } | 243 | } |
224 | 244 | ||
225 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1},colliding={2}", | 245 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1},colliding={2},isStationary={3}", |
226 | m_controllingPrim.LocalID, m_velocityMotor.TargetValue, m_controllingPrim.IsColliding); | 246 | m_controllingPrim.LocalID, m_velocityMotor.TargetValue, m_controllingPrim.IsColliding,m_controllingPrim.IsStationary); |
227 | } | 247 | } |
228 | else | 248 | else |
229 | { | 249 | { |
@@ -237,50 +257,24 @@ public class BSActorAvatarMove : BSActor | |||
237 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); | 257 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); |
238 | } | 258 | } |
239 | 259 | ||
240 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | 260 | // 'm_velocityMotor is used for walking, flying, and jumping and will thus have the correct values |
241 | { | 261 | // for Z. But in come cases it must be over-ridden. Like when falling or jumping. |
242 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | ||
243 | } | ||
244 | 262 | ||
245 | // Colliding and not flying with an upward force. The avatar must be trying to jump. | 263 | float realVelocityZ = m_controllingPrim.RawVelocity.Z; |
246 | if (!m_controllingPrim.Flying && m_controllingPrim.IsColliding && stepVelocity.Z > 0) | ||
247 | { | ||
248 | // We allow the upward force to happen for this many frames. | ||
249 | m_jumpFrames = BSParam.AvatarJumpFrames; | ||
250 | m_jumpVelocity = stepVelocity.Z; | ||
251 | } | ||
252 | 264 | ||
253 | // The case where the avatar is not colliding and is not flying is special. | 265 | // If not flying and falling, we over-ride the stepping motor so we can fall to the ground |
254 | // The avatar is either falling or jumping and the user can be applying force to the avatar | 266 | if (!m_controllingPrim.Flying && realVelocityZ < 0) |
255 | // (force in some direction or force up or down). | ||
256 | // If the avatar has negative Z velocity and is not colliding, presume we're falling and keep the velocity. | ||
257 | // If the user is trying to apply upward force but we're not colliding, assume the avatar | ||
258 | // is trying to jump and don't apply the upward force if not touching the ground any more. | ||
259 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | ||
260 | { | 267 | { |
261 | // If upward velocity is being applied, this must be a jump and only allow that to go on so long | 268 | // Can't fall faster than this |
262 | if (m_jumpFrames > 0) | 269 | if (realVelocityZ < BSParam.AvatarTerminalVelocity) |
263 | { | 270 | { |
264 | // Since not touching the ground, only apply upward force for so long. | 271 | realVelocityZ = BSParam.AvatarTerminalVelocity; |
265 | m_jumpFrames--; | ||
266 | stepVelocity.Z = m_jumpVelocity; | ||
267 | } | 272 | } |
268 | else | 273 | |
269 | { | 274 | stepVelocity.Z = realVelocityZ; |
270 | |||
271 | // Since we're not affected by anything, the avatar must be falling and we do not want that to be too fast. | ||
272 | if (m_controllingPrim.RawVelocity.Z < BSParam.AvatarTerminalVelocity) | ||
273 | { | ||
274 | |||
275 | stepVelocity.Z = BSParam.AvatarTerminalVelocity; | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | ||
280 | } | ||
281 | } | ||
282 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
283 | } | 275 | } |
276 | // m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,DEBUG,motorCurrent={1},realZ={2},flying={3},collid={4},jFrames={5}", | ||
277 | // m_controllingPrim.LocalID, m_velocityMotor.CurrentValue, realVelocityZ, m_controllingPrim.Flying, m_controllingPrim.IsColliding, m_jumpFrames); | ||
284 | 278 | ||
285 | //Alicia: Maintain minimum height when flying. | 279 | //Alicia: Maintain minimum height when flying. |
286 | // SL has a flying effect that keeps the avatar flying above the ground by some margin | 280 | // SL has a flying effect that keeps the avatar flying above the ground by some margin |
@@ -291,6 +285,8 @@ public class BSActorAvatarMove : BSActor | |||
291 | 285 | ||
292 | if( m_controllingPrim.Position.Z < hover_height) | 286 | if( m_controllingPrim.Position.Z < hover_height) |
293 | { | 287 | { |
288 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,addingUpforceForGroundMargin,height={1},hoverHeight={2}", | ||
289 | m_controllingPrim.LocalID, m_controllingPrim.Position.Z, hover_height); | ||
294 | stepVelocity.Z += BSParam.AvatarFlyingGroundUpForce; | 290 | stepVelocity.Z += BSParam.AvatarFlyingGroundUpForce; |
295 | } | 291 | } |
296 | } | 292 | } |