BulletSim: tweek step parameters and logic to make walking up steps

closer to SL. This change should address small floor edges acting like
walls, approaching a step at any angle (other than walking backwards)
will allow walking up, and reducing the avatar pop-up when going up
stairs.
sedebug
Robert Adams 2015-01-07 06:39:29 -08:00
parent 8e562f04d1
commit 700543b161
3 changed files with 39 additions and 12 deletions

View File

@ -341,7 +341,7 @@ public class BSActorAvatarMove : BSActor
// float nearFeetHeightMin = m_controllingPrim.RawPosition.Z - (m_controllingPrim.Size.Z / 2f) + 0.05f; // float nearFeetHeightMin = m_controllingPrim.RawPosition.Z - (m_controllingPrim.Size.Z / 2f) + 0.05f;
// Note: there is a problem with the computation of the capsule height. Thus RawPosition is off // Note: there is a problem with the computation of the capsule height. Thus RawPosition is off
// from the height. Revisit size and this computation when height is scaled properly. // from the height. Revisit size and this computation when height is scaled properly.
float nearFeetHeightMin = m_controllingPrim.RawPosition.Z - (m_controllingPrim.Size.Z / 2f) - 0.05f; float nearFeetHeightMin = m_controllingPrim.RawPosition.Z - (m_controllingPrim.Size.Z / 2f) - BSParam.AvatarStepGroundFudge;
float nearFeetHeightMax = nearFeetHeightMin + BSParam.AvatarStepHeight; float nearFeetHeightMax = nearFeetHeightMin + BSParam.AvatarStepHeight;
// Look for a collision point that is near the character's feet and is oriented the same as the charactor is. // Look for a collision point that is near the character's feet and is oriented the same as the charactor is.
@ -363,15 +363,25 @@ public class BSActorAvatarMove : BSActor
if (touchPosition.Z >= nearFeetHeightMin && touchPosition.Z <= nearFeetHeightMax) if (touchPosition.Z >= nearFeetHeightMin && touchPosition.Z <= nearFeetHeightMax)
{ {
// This contact is within the 'near the feet' range. // This contact is within the 'near the feet' range.
// The normal should be our contact point to the object so it is pointing away // The step is presumed to be more or less vertical. Thus the Z component should
// thus the difference between our facing orientation and the normal should be small. // be nearly horizontal.
OMV.Vector3 directionFacing = OMV.Vector3.UnitX * m_controllingPrim.RawOrientation; OMV.Vector3 directionFacing = OMV.Vector3.UnitX * m_controllingPrim.RawOrientation;
OMV.Vector3 touchNormal = OMV.Vector3.Normalize(kvp.Value.SurfaceNormal); OMV.Vector3 touchNormal = OMV.Vector3.Normalize(kvp.Value.SurfaceNormal);
float diff = Math.Abs(OMV.Vector3.Distance(directionFacing, touchNormal)); const float PIOver2 = 1.571f; // Used to make unit vector axis into approx radian angles
if (diff < BSParam.AvatarStepApproachFactor) // m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,avNormal={1},colNormal={2},diff={3}",
// m_controllingPrim.LocalID, directionFacing, touchNormal,
// Math.Abs(OMV.Vector3.Distance(directionFacing, touchNormal)) );
if ((Math.Abs(directionFacing.Z) * PIOver2) < BSParam.AvatarStepAngle
&& (Math.Abs(touchNormal.Z) * PIOver2) < BSParam.AvatarStepAngle)
{ {
if (highestTouchPosition.Z < touchPosition.Z) // The normal should be our contact point to the object so it is pointing away
highestTouchPosition = touchPosition; // thus the difference between our facing orientation and the normal should be small.
float diff = Math.Abs(OMV.Vector3.Distance(directionFacing, touchNormal));
if (diff < BSParam.AvatarStepApproachFactor)
{
if (highestTouchPosition.Z < touchPosition.Z)
highestTouchPosition = touchPosition;
}
} }
} }
} }

View File

@ -153,6 +153,8 @@ public static class BSParam
public static int AvatarJumpFrames { get; private set; } public static int AvatarJumpFrames { get; private set; }
public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } public static float AvatarBelowGroundUpCorrectionMeters { get; private set; }
public static float AvatarStepHeight { get; private set; } public static float AvatarStepHeight { get; private set; }
public static float AvatarStepAngle { get; private set; }
public static float AvatarStepGroundFudge { get; private set; }
public static float AvatarStepApproachFactor { get; private set; } public static float AvatarStepApproachFactor { get; private set; }
public static float AvatarStepForceFactor { get; private set; } public static float AvatarStepForceFactor { get; private set; }
public static float AvatarStepUpCorrectionFactor { get; private set; } public static float AvatarStepUpCorrectionFactor { get; private set; }
@ -614,13 +616,17 @@ public static class BSParam
new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.", new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.",
4 ), 4 ),
new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction", new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction",
0.6f ) , 0.999f ) ,
new ParameterDefn<float>("AvatarStepAngle", "The angle (in radians) for a vertical surface to be considered a step",
0.3f ) ,
new ParameterDefn<float>("AvatarStepGroundFudge", "Fudge factor subtracted from avatar base when comparing collision height",
0.1f ) ,
new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)",
0.6f ), 2f ),
new ParameterDefn<float>("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step", new ParameterDefn<float>("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step",
1.0f ), 0f ),
new ParameterDefn<float>("AvatarStepUpCorrectionFactor", "Multiplied by height of step collision to create up movement at step", new ParameterDefn<float>("AvatarStepUpCorrectionFactor", "Multiplied by height of step collision to create up movement at step",
2.0f ), 0.8f ),
new ParameterDefn<int>("AvatarStepSmoothingSteps", "Number of frames after a step collision that we continue walking up stairs", new ParameterDefn<int>("AvatarStepSmoothingSteps", "Number of frames after a step collision that we continue walking up stairs",
1 ), 1 ),

View File

@ -1070,6 +1070,17 @@
AvatarHeightMidFudge = 0 ; Adjustment at mid point of avatar height range AvatarHeightMidFudge = 0 ; Adjustment at mid point of avatar height range
AvatarHeightHighFudge = 0 ; Adjustment at high end of height range AvatarHeightHighFudge = 0 ; Adjustment at high end of height range
; Avatar walk-up-stairs parameters
; If an avatar collides with an object 'close to its feet', the avatar will be
; moved/pushed up do simulate stepping up.
;AvatarStepHeight = 0.6f ; The height, below which is considered a step collision.
;AvatarStepAngle = 0.3f ; The angle from vertical (in radians) to consider a surface a step
;AvatarStepApproachFactor = 2f ; Approach angle factor. O=straight on, .6=~45 degrees.
;AvatarStepGroundFudge = 0.1f ; Fudge added to bottom of avatar below which step collisions happen
;AvatarStepForceFactor = 0f ; Avatar is pushed up by its mass times this factor
;AvatarStepUpCorrectionFactor = 0.8f ; Avatar is displaced up the collision height times this factor
;AvatarStepSmoothingSteps = 1 ; Number of frames after a step collision that up correction is applied
; Terminal velocity of a falling avatar ; Terminal velocity of a falling avatar
; This is the same http://en.wikipedia.org/wiki/Terminal_velocity#Examples ; This is the same http://en.wikipedia.org/wiki/Terminal_velocity#Examples
; negative for a downward speed. ; negative for a downward speed.