I made a simple fps controller with the basic movement and jump functions. But I can’t figure out how to make the arms move with the camera movement.
This is the Player Movement Script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController playah;
public float speed = 12f;
public Transform GravityCheck;
public float jumpheight=3f;
public Animator anim;
public float gravity = -9.81f;
public LayerMask ground;
public float GroundDistance;
bool isGrounded;
Vector3 velocity;// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(GravityCheck.position, GroundDistance, ground);
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
if ( Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
{
anim.SetInteger("Condition", 1);
}
else
anim.SetInteger("Condition", 0);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
Vector3 move = transform.right * x + transform.forward * z;
playah.Move(move*speed*Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
playah.Move(velocity * Time.deltaTime);
if(Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpheight * -2f * gravity);
}
}
}
This is the Camera Script.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
// Start is called before the first frame update
public Transform PlayerBody;
public float MouseSensitivity;
float xrotation;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float MouseX = Input.GetAxis("Mouse X")*MouseSensitivity*Time.deltaTime;
float MouseY = Input.GetAxis("Mouse Y")*MouseSensitivity*Time.deltaTime;
xrotation -= MouseY;
xrotation = Mathf.Clamp(xrotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xrotation, 0, 0);
PlayerBody.Rotate(Vector3.up * MouseX);
}
}
So what should I do?