From 8a6338842a467bd4bdd2e1101290c161b4606cf2 Mon Sep 17 00:00:00 2001 From: Trey Shaw Date: Sat, 28 Feb 2026 10:45:50 -0600 Subject: [PATCH] fix gravity with door transition --- Assets/Scenes/SampleScene.unity | 6 +++--- Assets/Scripts/PlayerController.cs | 32 +++++++++++++++++++++++++++--- Assets/Scripts/TeleportHandler.cs | 8 ++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index d52dccd..46c6917 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -953,13 +953,13 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 151657444} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.475, y: 34.3, z: -0} + m_LocalRotation: {x: 0, y: 1, z: 0, w: 0} + m_LocalPosition: {x: -0.47499996, y: 34.3, z: 0.00000012626319} m_LocalScale: {x: 1.1708915, y: 69.57974, z: 1.1708915} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 441147620} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0} --- !u!114 &151657446 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index ac97f40..2ee0a87 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -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(); } /// - /// Handle movement + /// Apply walking inputs to moveDir /// - 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); } + } + /// + /// Apply gravity to moveDir + /// + void ApplyGravity() + { moveDir *= walkSpeed; if (!characterController.isGrounded) { moveDir.y = -gravity; } + } + /// + /// Move character with moveDir + /// + void DoMovement() + { characterController.Move(moveDir * Time.deltaTime); } + /// + /// Pass movement into character controller, lets us expose function without exposing + /// whole char controller + /// + public void CharacterControllerMove(Vector3 movement) + { + characterController.Move(movement); + } + /// /// Detect input for digging (will eventually be tool agnostic) /// diff --git a/Assets/Scripts/TeleportHandler.cs b/Assets/Scripts/TeleportHandler.cs index 6165ad1..6fc94d7 100644 --- a/Assets/Scripts/TeleportHandler.cs +++ b/Assets/Scripts/TeleportHandler.cs @@ -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)