using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movment : MonoBehaviour
[SerializeField] Transform playerCamara;
[SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
[SerializeField] bool cursorLock = true;
[SerializeField] float mouseSensitivity = 3.5f;
[SerializeField] float Speed = 6.0f;
[SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
[SerializeField] float gravity = 30f;
[SerializeField] Transform grouncheck;
[SerializeField] LayersMask ground;
public float jumpHeight = 6f;
float velocityY;
bool isGrounded;
float camaraCap;
Vector2 currentMouseDelta;
Vector2 currentMouseDeltaVelocity;
CharacterController controller;
Vector2 currnetDir;
Vector2 currentDirVelocity;
Vector2 velocity;
{
void Start()
{
controller = GetComponent<CharacterController>();
if (cursorLock)
{
Curoser.lockState = CursorLockMode.Locked;
cursorLock.Visable = true;
}
}
// Update is called once per frame
void Update()
{
UpdateMouse();
UpdateMove();
}
}
void UpdateMouse()
{
Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
camaraCap = currentMouseDelta.y * mouseSensitivity;
camaraCap = Mathf.Clamp(camaraCap, -90,0f, 90,0f);
playerCamara.localEulerAngles = Vector3.right * camaraCap;
transform.Roatate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
}
void UpdateMove()
{
isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, ground);
Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizantal"), Input.GetAxisRaw("Vertical"));
targetDir.Dir.Noramlize();
currnetDir = Vector2.SmoothDamp(currnetDir, targetDir, ref currentDirVelocity, mouseSmoothTime);
velocityY += gravity * 2f * Time.DeltaTime;
Vector3 velocity = (transform.forward * currnetDir.y * trasnform.right * currnetDir.x * Speed + Vector3.up * velocityY);
controller.Move(velocity * Time.DeltaTime);
if (isGrounded && Input.GetButtonDown("Jump"))
{
velocityY = Mathf.Sort(jumpHeight * -2f = gravity);
}
if (isGrounded! && controller.velocity.y < -1f)
{
velocity = -8f;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movment : MonoBehaviour
[SerializeField] Transform playerCamara;
[SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
[SerializeField] bool cursorLock = true;
[SerializeField] float mouseSensitivity = 3.5f;
[SerializeField] float Speed = 6.0f;
[SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
[SerializeField] float gravity = 30f;
[SerializeField] Transform grouncheck;
[SerializeField] LayersMask ground;
public float jumpHeight = 6f;
float velocityY;
bool isGrounded;
float camaraCap;
Vector2 currentMouseDelta;
Vector2 currentMouseDeltaVelocity;
CharacterController controller;
Vector2 currnetDir;
Vector2 currentDirVelocity;
Vector2 velocity;
{
void Start()
{
controller = GetComponent();
if (cursorLock)
{
Curoser.lockState = CursorLockMode.Locked;
cursorLock.Visable = true;
}
}
// Update is called once per frame
void Update()
{
UpdateMouse();
UpdateMove();
}
}
void UpdateMouse()
{
Vector2 targetMouseDelta = new Vector2(Input.GetAxis(âMouse Xâ), Input.GetAxis(âMouse Yâ));
currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
camaraCap = currentMouseDelta.y * mouseSensitivity;
camaraCap = Mathf.Clamp(camaraCap, -90,0f, 90,0f);
playerCamara.localEulerAngles = Vector3.right * camaraCap;
transform.Roatate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
}
void UpdateMove()
{
isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, ground);
Vector2 targetDir = new Vector2(Input.GetAxisRaw(âHorizantalâ), Input.GetAxisRaw(âVerticalâ));
targetDir.Dir.Noramlize();
currnetDir = Vector2.SmoothDamp(currnetDir, targetDir, ref currentDirVelocity, mouseSmoothTime);
velocityY += gravity * 2f * Time.DeltaTime;
Vector3 velocity = (transform.forward * currnetDir.y * trasnform.right * currnetDir.x * Speed + Vector3.up * velocityY);
controller.Move(velocity * Time.DeltaTime);
if (isGrounded && Input.GetButtonDown(âJumpâ))
{
velocityY = Mathf.Sort(jumpHeight * -2f = gravity);
}
if (isGrounded! && controller.velocity.y < -1f)
{
velocity = -8f;
}
}[/code]