So I’m Setting up My Animator Script and I Don’t Know I Couldn’t Find Much Animator Scripts That Could Help me ad To My Movement Script So Here It Is
using UnityEngine;
public class FPSFirstPerson : MonoBehaviour
{
public Transform camera;
public Rigidbody rb;
public Animator animator;
public float camRotationSpeed = 5f;
public float cameraMinimumY = -60f;
public float cameraMaximumY = 75f;
public float rotationSmoothSpeed = 10f;
public float walkSpeed = 9f;
public float runSpeed = 14f;
public float maxSpeed = 20f;
public float jumpPower = 30f;
public float _extraGravity = 45;
float bodyRotationX;
float camRotationY;
Vector3 directionIntentX;
Vector3 directionIntentY;
float speed;
public bool grounded;
public void Awake()
{
animator = GetComponent<Animator>();
}
void Update()
{
LookRotation();
Movement();
extraGravity();
GroundCheck();
if(grounded && Input.GetButtonDown("Jump"))
{
Jump();
}
}
void LookRotation()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
bodyRotationX += Input.GetAxis("Mouse X") * camRotationSpeed;
camRotationY += Input.GetAxis("Mouse Y") * camRotationSpeed;
camRotationY = Mathf.Clamp(camRotationY, cameraMinimumY, cameraMaximumY);
Quaternion camTargetRotation = Quaternion.Euler(-camRotationY, 0, 0);
Quaternion bodyTargetRotation = Quaternion.Euler(0, bodyRotationX, 0);
transform.rotation = Quaternion.Lerp(transform.rotation, bodyTargetRotation, Time.deltaTime * rotationSmoothSpeed);
camera.localRotation = Quaternion.Lerp(camera.localRotation, camTargetRotation, Time.deltaTime * rotationSmoothSpeed);
}
void Movement()
{
directionIntentX = camera.right;
directionIntentX.y = 0;
directionIntentX.Normalize();
directionIntentY = camera.forward;
directionIntentY.y = 0;
directionIntentY.Normalize();
rb.velocity = directionIntentY * Input.GetAxis("Vertical") * speed + directionIntentX * Input.GetAxis("Horizontal") * speed + Vector3.up * rb.velocity.y;
rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
if (directionIntentX != 0) animator.SetFloat("Fight Idle", true);
else animator.SetFloat("Walkingn", false);
if (directionIntentY != 0) animator.SetFloat("Fight Idle", true);
else animator.SetFloat("Walking", false);
if (directionIntentX != 1) animator.SetFloat("Walking", true);
else animator.SetFloat("Walking", false);
if (directionIntentY != 1) animator.SetFloat("Walking", true);
else animator.SetFloat("Walking", false);
if (directionIntentX != 2) animator.SetFloat("Run", true);
else animator.SetFloat("Run", false);
if (directionIntentY != 2) animator.SetFloat("Run", true);
else animator.SetFloat("Run", false);
if(Input.GetKey(KeyCode.LeftShift))
{
speed = runSpeed;
}
if(!Input.GetKey(KeyCode.LeftShift))
{
speed = walkSpeed;
}
}
void extraGravity()
{
rb.AddForce(Vector3.down * _extraGravity );
}
void GroundCheck()
{
RaycastHit groundHit;
grounded = Physics.Raycast(transform.position, -transform.up, out groundHit, 1.25f);
}
void Jump()
{
rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
}
}
So I Just Wanted To Have Anyone Correct It If, I got Anything Wrong Or Something to Change Any Help Given Thank You