protected float CalcSlopeSpeedAdjustment(float slopeSpeedMult, Vector3 playerInput, float speedUpEndAngle, float slowStartAngle, float maxWalkableAngle)
    {
        //get average slope normal from ground raycasts
        //if no successful raycasts, we're not on the ground and shouldn't adjust speed;
        //if no player input, also don't adjust speed (necessary?)
        if (!PlayerUtils.GroundRaycasts(playerFloor.transform.position, out Vector3 avgSlopeNormal, levelGeometrySolid) || playerInput.sqrMagnitude == 0f)
        {
            return(1);
        }

        //get angle between player input and slope normal; return speed multiplier based on this
        float angle = Vector3.Angle(playerInput, avgSlopeNormal) - 90f; //-90 so angle is between -90 and 90, with 0 being flat ground

        if (angle < speedUpEndAngle)
        {
            return(1 + ((1 - Mathf.InverseLerp(-90, speedUpEndAngle, angle)) * slopeSpeedMult));
        }
        if (angle > speedUpEndAngle && angle < slowStartAngle)
        {
            return(1);
        }
        if (angle < maxWalkableAngle)
        {
            return(1 - Mathf.InverseLerp(slowStartAngle, maxWalkableAngle, angle));
        }
        else
        {
            return(0f); //angle > max walkable angle
        }
    }
示例#2
0
 private void SetIsOnGround()
 {
     if (PlayerUtils.GroundRaycasts(playerFloor.transform.position, out Vector3 avgNormal, LayerMask.GetMask("LevelGeometrySolid")))
     {
         float avgGroundAngle = Vector3.Angle(avgNormal, Vector3.up);
         IsOnGround = avgGroundAngle < MAX_WALKABLE_ANGLE;
     }