Попробуй это:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float camSens = 0.25f;
private Vector3 lastMouse = Vector3.zero;
private Rigidbody rb;
public float speed = 6.0f;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
Vector3 mouseDelta = Input.mousePosition - lastMouse;
float mouseX = mouseDelta.x * camSens;
float mouseY = -mouseDelta.y * camSens;
lastMouse = Input.mousePosition;
Vector3 currentRotation = transform.rotation.eulerAngles;
currentRotation.y += mouseX;
transform.rotation = Quaternion.Euler(currentRotation);
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(horizontalInput, 0, verticalInput).normalized;
moveDirection = transform.TransformDirection(moveDirection);
Vector3 newPosition = rb.position + moveDirection * speed * Time.deltaTime;
rb.MovePosition(newPosition);
if (Input.GetKey("space"))
{
transform.position = Vector3.zero;
}
}
}