fix gravity with door transition
This commit is contained in:
@@ -29,6 +29,8 @@ void Start()
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
moveDir = Vector3.zero;
|
||||
|
||||
if (hasControl)
|
||||
{
|
||||
if (!isDigging)
|
||||
@@ -37,8 +39,8 @@ void Update()
|
||||
TryInteract();
|
||||
}
|
||||
|
||||
Walk();
|
||||
DigDetector();
|
||||
ApplyWalk();
|
||||
|
||||
// TODO: This is just for testing, remove or clean up if used
|
||||
if (Input.GetKeyDown(KeyCode.LeftShift))
|
||||
@@ -46,12 +48,15 @@ void Update()
|
||||
cameraController.RotateCam();
|
||||
}
|
||||
}
|
||||
|
||||
ApplyGravity();
|
||||
DoMovement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle movement
|
||||
/// Apply walking inputs to moveDir
|
||||
/// </summary>
|
||||
void Walk()
|
||||
void ApplyWalk()
|
||||
{
|
||||
float verticalMovement = 0;
|
||||
float horizontalMovement = 0;
|
||||
@@ -72,17 +77,38 @@ void Walk()
|
||||
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
||||
moveDir = matrix.MultiplyPoint3x4(moveDir);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply gravity to moveDir
|
||||
/// </summary>
|
||||
void ApplyGravity()
|
||||
{
|
||||
moveDir *= walkSpeed;
|
||||
|
||||
if (!characterController.isGrounded)
|
||||
{
|
||||
moveDir.y = -gravity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move character with moveDir
|
||||
/// </summary>
|
||||
void DoMovement()
|
||||
{
|
||||
characterController.Move(moveDir * Time.deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pass movement into character controller, lets us expose function without exposing
|
||||
/// whole char controller
|
||||
/// </summary>
|
||||
public void CharacterControllerMove(Vector3 movement)
|
||||
{
|
||||
characterController.Move(movement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect input for digging (will eventually be tool agnostic)
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user