浏览代码

Update Character.cs

/main
mwert09 4 年前
当前提交
14215282
共有 1 个文件被更改,包括 19 次插入3 次删除
  1. 22
      UOP1_Project/Assets/Scripts/Characters/Character.cs

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


private bool shouldSlide; // Should player slide?
private Vector3 inputVector; //Initial input horizontal movement (y == 0f)
private Vector3 movementVector; //Final movement vector
private void Awake()
{
characterController = GetComponent<CharacterController>();

gravityContributionMultiplier = 0f;
}
}
UpdateSlide();
//Apply the result and move the character in space
movementVector.y = verticalMovement;
characterController.Move(movementVector * Time.deltaTime);

{
isJumping = false; //This will stop the reduction to the gravity, which will then quickly pull down the character
}
}
private void UpdateSlide()
{
// if player has to slide then add sideways speed to make it go down
if (shouldSlide)
{
movementVector.x += (1f - hitNormal.y) * hitNormal.x * (speed - slideFriction);
movementVector.z += (1f - hitNormal.y) * hitNormal.z * (speed - slideFriction);
}
// check if the controller is grounded and above slope limit
// if player is grounded and above slope limit
// player has to slide
currentSlope = Vector3.Angle(Vector3.up, hitNormal);
shouldSlide = currentSlope >= characterController.slopeLimit;
}
}
正在加载...
取消
保存