diff --git a/Assets/Materials/leaf.mat b/Assets/Materials/leaf.mat index 7e8c3b7..ab1d39e 100644 --- a/Assets/Materials/leaf.mat +++ b/Assets/Materials/leaf.mat @@ -20,7 +20,8 @@ Material: m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} - disabledShaderPasses: [] + disabledShaderPasses: + - MOTIONVECTORS m_LockedProperties: m_SavedProperties: serializedVersion: 3 diff --git a/Assets/PlayerControls.inputactions b/Assets/PlayerControls.inputactions index a30477b..1575dd9 100644 --- a/Assets/PlayerControls.inputactions +++ b/Assets/PlayerControls.inputactions @@ -41,6 +41,24 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Look", + "type": "Value", + "id": "7fba5b60-8d24-49b6-8308-c70e6a63c456", + "expectedControlType": "Vector2", + "processors": "", + "interactions": "", + "initialStateCheck": true + }, + { + "name": "Run", + "type": "Button", + "id": "5a6630db-ebaf-4fde-9e52-f04136a77988", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -175,6 +193,50 @@ "action": "Pause", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "74ebb1b9-ab13-42d0-956f-019b25fb646b", + "path": "/rightStick", + "interactions": "", + "processors": "", + "groups": "", + "action": "Look", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "2c4bb4fd-6d38-4424-a2de-e798aeef5dd7", + "path": "/delta", + "interactions": "", + "processors": "", + "groups": "", + "action": "Look", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "ac8271b8-5a0c-498a-b97b-57546775b0b9", + "path": "/leftStickPress", + "interactions": "", + "processors": "", + "groups": "", + "action": "Run", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "34fcda37-2f7d-40e9-a510-fff20ecd0672", + "path": "/leftShift", + "interactions": "", + "processors": "", + "groups": "", + "action": "Run", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/Assets/Scenes/Scene1-1.unity b/Assets/Scenes/Scene1-1.unity index 5a01207..aa0b5a9 100644 --- a/Assets/Scenes/Scene1-1.unity +++ b/Assets/Scenes/Scene1-1.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e78cc88f3aacf7d6c2aa208589c0a62be24b44cefd6a9feeb19001d75c897c3 -size 1416414 +oid sha256:5fcdb460f80cc0909eec92f627019859c2e32912d802b1e86ed3e335d32044ae +size 1418572 diff --git a/Assets/Scripts/PlayerCam.cs b/Assets/Scripts/PlayerCam.cs index 4c8b93e..ee78ecb 100644 --- a/Assets/Scripts/PlayerCam.cs +++ b/Assets/Scripts/PlayerCam.cs @@ -5,10 +5,10 @@ public class PlayerCam : MonoBehaviour { float sens; public Transform orientation; + public Transform player; float xRotation; float yRotation; - float mouseX; - float mouseY; + public Vector2 lookInput; public Transform wagonRot; private Quaternion previousSourceRotation; @@ -51,19 +51,19 @@ public class PlayerCam : MonoBehaviour sens = Sensitivity.value; if (canLook) { - mouseX = Input.GetAxis("Mouse X") * sens; - mouseY = Input.GetAxis("Mouse Y") * sens; + yRotation += lookInput.x * sens * Time.deltaTime; + xRotation -= lookInput.y * sens * Time.deltaTime; } - yRotation += mouseX; - xRotation -= mouseY; + xRotation = Mathf.Clamp(xRotation, -87f, 87f); transform.rotation = Quaternion.Euler(xRotation, yRotation, 0); orientation.rotation = Quaternion.Euler(0, yRotation, 0); + player.rotation = Quaternion.Euler(0, yRotation, 0); } } diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index ef77ca8..7d64717 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -30,7 +30,6 @@ public class PlayerMovement : MonoBehaviour public InputAction pauseGameButton; - public Transform orientation; public Transform cameraor; @@ -47,6 +46,7 @@ public class PlayerMovement : MonoBehaviour public float timeSinceLastSwing; public bool holdSwing; public float holdSwingTimer; + public bool swingBeingHeld; public float dashDistanceTimer, dashDistance, dashDuration; public Collider myCollider; @@ -64,7 +64,7 @@ public class PlayerMovement : MonoBehaviour float energyObjTimer; public GameObject energyFill; - + public bool jumped; @@ -85,12 +85,65 @@ public class PlayerMovement : MonoBehaviour void Update() { - MyInput(); - if (pauseGameButton.WasPerformedThisFrame()) + + timeSinceLastSwing += Time.deltaTime; + if (timeSinceLastSwing > .5f) + lastSwing = 0; + + holdSwingTimer += Time.deltaTime; + if (holdSwing && holdSwingTimer > .15f) + holdSwing = false; + else if (holdSwing && GameObject.FindGameObjectsWithTag("Sword").Length < 1) { + holdSwing = false; + if (energy > 7) + SwingSword(); + } + if (!holdSwing) + holdSwingTimer = 0; + + if (swung) + { + swungTimer += Time.deltaTime; + } + if (swungTimer > 1f) + swung = false; + if (!swung) + { + swungTimer = 0; + energy += 70 * Time.deltaTime; } + if (energy < 0) + energy = 0; + if (energy > 100) + energy = 100; + energySlider.value = energy; + + healthUI.sizeDelta = new Vector2((Mathf.Ceil(HP) - 1) + (9 * HP), healthUI.sizeDelta.y); + + //MyInput(); + if (swingBeingHeld) + { + swung = true; + swungTimer = 0; + timeSinceLastSwing = 0; + + energy -= 20 * Time.deltaTime; + dashDistanceTimer += Time.deltaTime; + if (dashDistanceTimer > 1) + energyFill.GetComponent().color = Color.deepPink; + if (energy <= 0) + { + if (dashDistanceTimer > 1) + { + dashDistance = Mathf.Floor(dashDistanceTimer * 8); + dashDuration = 15; + } + dashDistanceTimer = 0; + } + } if (energy == 100) { @@ -106,9 +159,46 @@ public class PlayerMovement : MonoBehaviour energyObjTimer = 0; energyObj.SetActive(true); } - } - void FixedUpdate() - { + + + + if (dashDuration > 0) + { + SwordDash(); + + dashDuration--; + } + if (dashDuration == 1) + { + //rb.linearVelocity = Vector3.zero; + + dashDuration--; + } + + + + if (canWalk /*&& !running*/) + { + Vector3 move = new Vector3(moveInput.x * speed, 0, moveInput.y * speed); + Vector3 move2 = transform.TransformDirection(move); + controller.Move(move2 * Time.deltaTime); + } + //else if (canWalk && running) + //{ + // Vector3 move = new Vector3(moveInput.x * speed, 0, moveInput.y * runSpeed); + // Vector3 move2 = transform.TransformDirection(move); + // controller.Move(move2 * Time.deltaTime); + //} + controller.Move(velocity * Time.deltaTime); + if (!controller.isGrounded) + { + velocity.y += gravity * Time.deltaTime; + } + else if (controller.isGrounded) + { + //velocity.y = 0; + } + } public void PauseGame(InputAction.CallbackContext context) @@ -131,6 +221,72 @@ public class PlayerMovement : MonoBehaviour Cursor.visible = false; } } + public void OnMove(InputAction.CallbackContext context) + { + moveInput = context.ReadValue(); + } + public void OnRun(InputAction.CallbackContext context) + { + if (context.performed && moveAnimationInputY == 1 && !running) + { + running = true; + } + else if (context.performed && moveAnimationInputY == 2 && running) + { + running = false; + moveAnimationInputY = 1; + } + if (context.canceled) + { + //running = false; + } + } + public void OnLook(InputAction.CallbackContext context) + { + playerCam.lookInput = context.ReadValue(); + } + public void OnAttack(InputAction.CallbackContext context) + { + if (context.performed && inventorySlot == 1) + { + swingBeingHeld = true; + if (GameObject.FindGameObjectsWithTag("Sword").Length < 1) + { + if (energy > 7) + SwingSword(); + } + else + { + swung = true; + swungTimer = 0; + holdSwingTimer = 0; + holdSwing = true; + } + } + if (context.canceled && inventorySlot == 1) + { + swingBeingHeld = false; + energyFill.GetComponent().color = Color.darkRed; + if (dashDistanceTimer > 1) + { + dashDistance = Mathf.Floor(dashDistanceTimer * 8); + dashDuration = 15; + } + dashDistanceTimer = 0; + } + } + public void OnJump(InputAction.CallbackContext context) + { + if (context.performed && controller.isGrounded) + { + velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity); + jumped = true; + } + if (context.canceled && !controller.isGrounded) + { + jumped = false; + } + } private void MyInput() { @@ -294,7 +450,7 @@ public class PlayerMovement : MonoBehaviour private void SwordDash() { myCollider.excludeLayers = excludeEnemy; - + Debug.Log($"distance:{dashDistance}"); //rb.AddForce(Camera.main.transform.forward * dashDistance, ForceMode.Impulse); swung = true; swungTimer = 0;