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>
|
||||
|
||||
@@ -33,7 +33,11 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
|
||||
Color blackScreenColor = Color.black;
|
||||
|
||||
playerController.SetCharacterControl(false);
|
||||
// Play enter room animation (wait seconds during animation)
|
||||
// Don't use the Y axis to look at the door
|
||||
Vector3 positionToLookAt = new Vector3(door.transform.position.x, playerController.DougBody.transform.position.y, door.transform.position.z);
|
||||
playerController.DougBody.transform.LookAt(positionToLookAt);
|
||||
|
||||
// Play door open animation
|
||||
if (door.requiresInteraction)
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
@@ -47,7 +51,7 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
|
||||
}
|
||||
fadeTime = 0;
|
||||
|
||||
transform.position = door.linkedDoor.transform.position;
|
||||
playerController.CharacterControllerMove(door.linkedDoor.transform.position - transform.position);
|
||||
playerController.DougBody.transform.rotation = door.linkedDoor.transform.rotation;
|
||||
|
||||
while (fadeTime < fadeDuration)
|
||||
|
||||
Reference in New Issue
Block a user