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.
cpu-performance
Robert Adams 2013-06-20 09:55:40 -07:00
parent a33b6eed6d
commit bbeff4b8ca
2 changed files with 42 additions and 5 deletions

View File

@ -43,8 +43,14 @@ public class BSActorAvatarMove : BSActor
// Set to true if we think we're going up stairs.
// This state is remembered because collisions will turn on and off as we go up stairs.
int m_walkingUpStairs;
// The amount the step up is applying. Used to smooth stair walking.
float m_lastStepUp;
// Jumping happens over several frames. If use applies up force while colliding, start the
// jump and allow the jump to continue for this number of frames.
int m_jumpFrames = 0;
float m_jumpVelocity = 0f;
public BSActorAvatarMove(BSScene physicsScene, BSPhysObject pObj, string actorName)
: base(physicsScene, pObj, actorName)
{
@ -206,17 +212,45 @@ public class BSActorAvatarMove : BSActor
if (m_controllingPrim.Friction != BSParam.AvatarFriction)
{
// Probably starting up walking. Set friction to moving friction.
// Probably starting to walk. Set friction to moving friction.
m_controllingPrim.Friction = BSParam.AvatarFriction;
m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction);
}
// If falling, we keep the world's downward vector no matter what the other axis specify.
// The check for RawVelocity.Z < 0 makes jumping work (temporary upward force).
if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding)
{
if (m_controllingPrim.RawVelocity.Z < 0)
stepVelocity.Z = m_controllingPrim.RawVelocity.Z;
}
// Colliding and not flying with an upward force. The avatar must be trying to jump.
if (!m_controllingPrim.Flying && m_controllingPrim.IsColliding && stepVelocity.Z > 0)
{
// We allow the upward force to happen for this many frames.
m_jumpFrames = BSParam.AvatarJumpFrames;
m_jumpVelocity = stepVelocity.Z;
}
// The case where the avatar is not colliding and is not flying is special.
// The avatar is either falling or jumping and the user can be applying force to the avatar
// (force in some direction or force up or down).
// If the avatar has negative Z velocity and is not colliding, presume we're falling and keep the velocity.
// If the user is trying to apply upward force but we're not colliding, assume the avatar
// is trying to jump and don't apply the upward force if not touching the ground any more.
if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding)
{
// If upward velocity is being applied, this must be a jump and only allow that to go on so long
if (m_jumpFrames > 0)
{
// Since not touching the ground, only apply upward force for so long.
m_jumpFrames--;
stepVelocity.Z = m_jumpVelocity;
}
else
{
// Since we're not affected by anything, whatever vertical motion the avatar has, continue that.
stepVelocity.Z = m_controllingPrim.RawVelocity.Z;
}
// DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
}
@ -241,7 +275,7 @@ public class BSActorAvatarMove : BSActor
m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,IsColliding={1},flying={2},targSpeed={3},collisions={4},avHeight={5}",
m_controllingPrim.LocalID, m_controllingPrim.IsColliding, m_controllingPrim.Flying,
m_controllingPrim.TargetVelocitySpeed, m_controllingPrim.CollisionsLastTick.Count, m_controllingPrim.Size.Z);
// This test is done if moving forward, not flying and is colliding with something.
// Check for stairs climbing if colliding, not flying and moving forward
if ( m_controllingPrim.IsColliding
&& !m_controllingPrim.Flying

View File

@ -134,6 +134,7 @@ public static class BSParam
public static float AvatarHeightMidFudge { get; private set; }
public static float AvatarHeightHighFudge { get; private set; }
public static float AvatarContactProcessingThreshold { get; private set; }
public static int AvatarJumpFrames { get; private set; }
public static float AvatarBelowGroundUpCorrectionMeters { get; private set; }
public static float AvatarStepHeight { get; private set; }
public static float AvatarStepApproachFactor { get; private set; }
@ -567,6 +568,8 @@ public static class BSParam
0.1f ),
new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground",
1.0f ),
new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.",
4 ),
new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction",
0.6f ) ,
new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)",