How To Get Player Arms To Be On The Same Up Down Coordinate As The Crosshair
I have some player arms that turn left and right when I move my player in my 3D FPS game. I would like the same to happen for the top down .
//Simple 3D FPS controller using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(CharacterController))] public class Player : MonoBehaviour { public Slider sliderHealth; public Slider sliderShield; public Transform gunPos; public Animator playerAnimator; public float walkingSpeed = 7.5f; public float runningSpeed = 11.5f; public float jumpSpeed = 8.0f; public float gravity = 15.5f; public Camera playerCamera; public float lookSpeed = 1.35f; public float lookXLimit = 60.0f; public float playerHealth = 100f; public float playerShield = 60; CharacterController characterController; Vector3 moveDirection = Vector3.zero; float rotationX = 0; [HideInInspector] public bool canMove = true; public void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("EnemyBullet")) { playerHealth -= 20f; } } void Start() { characterController = GetComponent<CharacterController>(); // Lock cursor Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } void Update() { gunPos.position = playerCamera.transform.position; sliderHealth.value = playerHealth; sliderShield.value = playerShield; // if the player presses w key if (Input.GetKey("w")) { // then set the isWalking boolean to be true playerAnimator.SetBool("isWalking", true); } if (!Input.GetKey("w")) { // then set the isWalking boolean to be false playerAnimator.SetBool("isWalking", false); } //Checking for the jump animator if (characterController.isGrounded) { playerAnimator.SetBool("isJumping", false); } // if the player presses space key if (Input.GetKey(KeyCode.Space) && characterController.isGrounded) { // then set the isWalking boolean to be true playerAnimator.SetBool("isJumping", true); // overide isWalking animation for jump playerAnimator.SetBool("isWalking", false); } if (!Input.GetKey(KeyCode.Space)) { // then set the isWalking boolean to be false playerAnimator.SetBool("isJumping", false); } if (Input.GetMouseButton(1)) { //set the animator playerAnimator.SetBool("isShooting", true); playerAnimator.SetBool("isJumping", false); playerAnimator.SetBool("isWalking", false); playerAnimator.SetBool("isPunching", false); } if (!Input.GetMouseButton(1)) { //set the animator playerAnimator.SetBool("isShooting", false); } if (Input.GetKey("f")) { // then set the animator playerAnimator.SetBool("isPunching", true); // overide isWalking animation for punch playerAnimator.SetBool("isWalking", false); // overide isJumping animation for punch playerAnimator.SetBool("isJumping", false); } if (!Input.GetKey("f")) { // then set the animator playerAnimator.SetBool("isPunching", false); } if (Input.GetKey("s")) { playerAnimator.SetBool("isBackwards", true); } if (!Input.GetKey("s")) { playerAnimator.SetBool("isBackwards", false); } if (Input.GetKey("a")) { playerAnimator.SetBool("IsLeftWalking", true); } if (!Input.GetKey("a")) { playerAnimator.SetBool("IsLeftWalking", false); } if (Input.GetKey("d")) { playerAnimator.SetBool("isRightWalking", true); } if (!Input.GetKey("d")) { playerAnimator.SetBool("isRightWalking", false); } // We are grounded, so recalculate move direction based on axes Vector3 forward = transform.TransformDirection(Vector3.forward); Vector3 right = transform.TransformDirection(Vector3.right); // Press Left Shift to run bool isRunning = Input.GetKey(KeyCode.LeftShift); float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0; float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0; float movementDirectionY = moveDirection.y; moveDirection = (forward * curSpeedX) + (right * curSpeedY); if (Input.GetButton("Jump") && canMove && characterController.isGrounded) { moveDirection.y = jumpSpeed; } else { moveDirection.y = movementDirectionY; } // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied // as an acceleration (ms^-2) if (!characterController.isGrounded) { moveDirection.y -= gravity * Time.deltaTime; } // Move the controller characterController.Move(moveDirection * Time.deltaTime); // Player and Camera rotation if (canMove) { rotationX += -Input.GetAxis("Mouse Y") * lookSpeed; rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit); playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0); transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0); } } }