feat: player can look around on all axis

This commit is contained in:
2026-02-24 09:50:15 +01:00
parent 44e13f4837
commit fe7550d9e2
1839 changed files with 112504 additions and 3767 deletions

View File

@@ -133,6 +133,7 @@ GameObject:
- component: {fileID: 125071002}
- component: {fileID: 125071001}
- component: {fileID: 125071000}
- component: {fileID: 125071003}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@@ -214,6 +215,20 @@ Transform:
m_Children: []
m_Father: {fileID: 1680796422}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &125071003
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 125070999}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 884f7e9cec877e7bb994f6c21263233f, type: 3}
m_Name:
m_EditorClassIdentifier:
mouseSensitivity: 20
playerBody: {fileID: 1680796422}
--- !u!1 &420667094
GameObject:
m_ObjectHideFlags: 0
@@ -738,8 +753,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
controller: {fileID: 1680796425}
speed: 10
mouseSensitivity: 100
playerBody: {fileID: 1680796422}
--- !u!143 &1680796425
CharacterController:
m_ObjectHideFlags: 0

View File

@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private InputMaster _inputMaster;
[SerializeField] private float mouseSensitivity = 20f;
[SerializeField] private Transform playerBody;
private float _mouseX, _mouseY;
private float xRotation;
private void Awake()
{
_inputMaster = new InputMaster();
_inputMaster.Player.Look.Enable();
}
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
var mousevalue = _inputMaster.Player.Look.ReadValue<Vector2>();
_mouseX = mousevalue.x * mouseSensitivity * Time.deltaTime;
_mouseY = mousevalue.y * mouseSensitivity * Time.deltaTime;
xRotation -= _mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * _mouseX);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 884f7e9cec877e7bb994f6c21263233f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,10 +8,6 @@ public class PlayerMovement : MonoBehaviour
private InputMaster _inputMaster;
[SerializeField] private CharacterController controller;
[SerializeField] private float speed;
[SerializeField] private float mouseSensitivity = 20f;
[SerializeField] private Transform playerBody;
private float _mouseX, _mouseY;
private Vector2 _moveDirection;
@@ -19,18 +15,9 @@ public class PlayerMovement : MonoBehaviour
{
controller = GetComponent<CharacterController>();
_inputMaster = new InputMaster();
_inputMaster.Player.Look.Enable();
_inputMaster.Player.Move.Enable();
}
private void Update()
{
var mousevalue = _inputMaster.Player.Look.ReadValue<Vector2>();
_mouseX = mousevalue.x * mouseSensitivity * Time.deltaTime;
_mouseY = mousevalue.y * mouseSensitivity * Time.deltaTime;
playerBody.Rotate(Vector3.up * _mouseX);
}
public void OnMove(InputAction.CallbackContext context)
{
_moveDirection = context.ReadValue<Vector2>();