浏览代码

Replace magic numbers with variables - issue: 40

/main
Andrew Real 4 年前
当前提交
1f6fdb42
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 8
      UOP1_Project/Assets/Scripts/Characters/Character.cs

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


public class Character : MonoBehaviour
{
private CharacterController characterController;
[Tooltip("Horizontal XZ plane speed multiplier")] public float speed = 8f;

[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 float rotationSensitivity = .02f;
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 >= rotationSensitivity)
{
float targetRotation = Mathf.Atan2(movementVector.x, movementVector.z) * Mathf.Rad2Deg;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(

正在加载...
取消
保存