From 7818d29bf05e3494f29d701bf601a423b53fdbce Mon Sep 17 00:00:00 2001 From: haitem Date: Fri, 28 Jan 2022 21:05:41 +0100 Subject: [PATCH] Update PlayerController.cs --- Assets/PlayerController.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Assets/PlayerController.cs b/Assets/PlayerController.cs index 12c7b8b..69d4c24 100644 --- a/Assets/PlayerController.cs +++ b/Assets/PlayerController.cs @@ -18,6 +18,8 @@ public class PlayerController : MonoBehaviour bool canMove = true; Rigidbody rb; + float moveDirectionY; + public Vector3 jump; public float jumpForce = 2.0f; @@ -38,26 +40,20 @@ public class PlayerController : MonoBehaviour playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0); transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0); - Vector3 forward = transform.TransformDirection(Vector3.forward); - Vector3 right = transform.TransformDirection(Vector3.right); - bool isRunning = Input.GetKey(KeyCode.LeftShift); float curSpeedX = canMove ? (isRunning ? runningSpeed : walkSpeed) * Input.GetAxis("Vertical") : 0; float curSpeedY = canMove ? (isRunning ? runningSpeed : walkSpeed) * Input.GetAxis("Horizontal") : 0; - float moveDirectionY = moveDirection.y; + moveDirection = (transform.forward * curSpeedX * Time.deltaTime) + (transform.right * curSpeedY * Time.deltaTime); if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Jump"); - moveDirection.y += jumpSpeed; - } - else - { - moveDirection.y = moveDirectionY; + rb.AddForce(transform.up * jumpSpeed * 500 * Time.deltaTime, ForceMode.Impulse); } - moveDirection = (forward * curSpeedX) + (right * curSpeedY); - characterController.Move(moveDirection * Time.deltaTime); + rb.MovePosition(rb.position + moveDirection); + + //characterController.Move(moveDirection * Time.deltaTime); } }