浏览代码

Merge pull request #55 from andrewreal/remove-magic-numbers

Remove magic numbers
/main
GitHub 4 年前
当前提交
02d8e6c7
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 7
      UOP1_Project/Assets/Scripts/Characters/Character.cs

7
UOP1_Project/Assets/Scripts/Characters/Character.cs


[Tooltip("Represents how fast gravityContributionMultiplier will go back to 1f. The higher, the faster")] public float gravityComebackMultiplier = 15f;
[Tooltip("The maximum speed reached when falling (in units/frame)")] public float maxFallSpeed = 50f;
[Tooltip("Each frame while jumping, gravity will be multiplied by this amount in an attempt to 'cancel it' (= jump higher)")] public float gravityDivider = .6f;
[Tooltip("Starting vertical movement when falling from a platform")] public float fallingVerticalMovement = -5f;
private float gravityContributionMultiplier = 0f; //The factor which determines how much gravity is affecting verticalMovement
private bool isJumping = false; //If true, a jump is in effect and the player is holding the jump button

private Vector3 inputVector; //Initial input horizontal movement (y == 0f)
private Vector3 movementVector; //Final movement vector
private const float ROTATION_TRESHOLD = .02f; // Used to prevent NaN result causing rotation in a non direction
private void Awake()
{

//-5f is a good value to make it so the player also sticks to uneven terrain/bumps without floating.
if (!isJumping)
{
verticalMovement = -5f;
verticalMovement = fallingVerticalMovement;
gravityContributionMultiplier = 0f;
}
}

//Rotate to the movement direction
movementVector.y = 0f;
if (movementVector.sqrMagnitude >= .02f)
if (movementVector.sqrMagnitude >= ROTATION_TRESHOLD)
{
float targetRotation = Mathf.Atan2(movementVector.x, movementVector.z) * Mathf.Rad2Deg;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(

正在加载...
取消
保存