feat: rotate the player camera to the side with the mouse

This commit is contained in:
2026-02-24 09:33:08 +01:00
parent 227f8bde40
commit 44e13f4837
10 changed files with 1849 additions and 27 deletions

1505
Assets/Input/InputMaster.cs Normal file

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,6 +1,6 @@
{ {
"version": 1, "version": 1,
"name": "OMG", "name": "InputMaster",
"maps": [ "maps": [
{ {
"name": "Player", "name": "Player",
@@ -180,22 +180,22 @@
}, },
{ {
"name": "", "name": "",
"id": "8c8e490b-c610-4785-884f-f04217b23ca4", "id": "3e5f5442-8668-4b27-a940-df99bad7e831",
"path": "<Pointer>/delta", "path": "<Joystick>/{Hatswitch}",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": ";Keyboard&Mouse;Touch", "groups": "Joystick",
"action": "Look", "action": "Look",
"isComposite": false, "isComposite": false,
"isPartOfComposite": false "isPartOfComposite": false
}, },
{ {
"name": "", "name": "",
"id": "3e5f5442-8668-4b27-a940-df99bad7e831", "id": "79d18aab-c726-4645-8a8b-f39d1e96e67e",
"path": "<Joystick>/{Hatswitch}", "path": "<Mouse>/delta",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "Joystick", "groups": "",
"action": "Look", "action": "Look",
"isComposite": false, "isComposite": false,
"isPartOfComposite": false "isPartOfComposite": false

View File

@@ -8,7 +8,7 @@ ScriptedImporter:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0 generateWrapperCode: 1
wrapperCodePath: wrapperCodePath:
wrapperClassName: wrapperClassName:
wrapperCodeNamespace: wrapperCodeNamespace:

83
Assets/Mat.mat Normal file
View File

@@ -0,0 +1,83 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Mat
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0.20736837, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

8
Assets/Mat.mat.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4e083d038de05807b8251393125f9200
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

83
Assets/Player.mat Normal file
View File

@@ -0,0 +1,83 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Player
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

8
Assets/Player.mat.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 55ecce37ebb44f3e7ab364e7c831da79
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -208,11 +208,116 @@ Transform:
m_GameObject: {fileID: 125070999} m_GameObject: {fileID: 125070999}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10} m_LocalPosition: {x: 0, y: 0.76, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 1680796422}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &420667094
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 420667098}
- component: {fileID: 420667097}
- component: {fileID: 420667096}
- component: {fileID: 420667095}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &420667095
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420667094}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &420667096
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420667094}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 4e083d038de05807b8251393125f9200, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &420667097
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420667094}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &420667098
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420667094}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.3796791, y: 2.94, z: -0.35401067}
m_LocalScale: {x: 0.013368983, y: 4.7461, z: 0.013368983}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 463387416}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &463387412 --- !u!1 &463387412
GameObject: GameObject:
@@ -314,9 +419,10 @@ Transform:
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 20, y: 1, z: 20} m_LocalScale: {x: 74.8, y: 1, z: 74.8}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children:
- {fileID: 420667098}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &574677457 --- !u!1 &574677457
@@ -478,7 +584,7 @@ MeshRenderer:
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 2100000, guid: 55ecce37ebb44f3e7ab364e7c831da79, type: 2}
m_StaticBatchInfo: m_StaticBatchInfo:
firstSubMesh: 0 firstSubMesh: 0
subMeshCount: 0 subMeshCount: 0
@@ -516,13 +622,14 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1680796418} m_GameObject: {fileID: 1680796418}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: -0.80701184, z: 0, w: 0.59053534}
m_LocalPosition: {x: 0, y: 1.52, z: 0} m_LocalPosition: {x: 0, y: 2.23, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1.2, y: 1.8, z: 1.2}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children:
- {fileID: 125071002}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: -107.61, z: 0}
--- !u!114 &1680796423 --- !u!114 &1680796423
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -550,13 +657,13 @@ MonoBehaviour:
m_ActionEvents: m_ActionEvents:
- m_PersistentCalls: - m_PersistentCalls:
m_Calls: m_Calls:
- m_Target: {fileID: 11500000, guid: abf8abec29a380b62a51f97e17907845, type: 3} - m_Target: {fileID: 1680796424}
m_TargetAssemblyTypeName: m_TargetAssemblyTypeName: PlayerMovement, Assembly-CSharp
m_MethodName: m_MethodName: OnMove
m_Mode: 1 m_Mode: 0
m_Arguments: m_Arguments:
m_ObjectArgument: {fileID: 0} m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0 m_IntArgument: 0
m_FloatArgument: 0 m_FloatArgument: 0
m_StringArgument: m_StringArgument:
@@ -631,6 +738,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
controller: {fileID: 1680796425} controller: {fileID: 1680796425}
speed: 10 speed: 10
mouseSensitivity: 100
playerBody: {fileID: 1680796422}
--- !u!143 &1680796425 --- !u!143 &1680796425
CharacterController: CharacterController:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -650,8 +759,8 @@ CharacterController:
m_ProvidesContacts: 0 m_ProvidesContacts: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Height: 2 m_Height: 3.8
m_Radius: 0.5 m_Radius: 0.6
m_SlopeLimit: 45 m_SlopeLimit: 45
m_StepOffset: 0.3 m_StepOffset: 0.3
m_SkinWidth: 0.08 m_SkinWidth: 0.08
@@ -661,7 +770,6 @@ CharacterController:
SceneRoots: SceneRoots:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_Roots: m_Roots:
- {fileID: 125071002}
- {fileID: 574677459} - {fileID: 574677459}
- {fileID: 463387416} - {fileID: 463387416}
- {fileID: 1680796422} - {fileID: 1680796422}

View File

@@ -5,14 +5,30 @@ using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour public class PlayerMovement : MonoBehaviour
{ {
private InputMaster _inputMaster;
[SerializeField] private CharacterController controller; [SerializeField] private CharacterController controller;
[SerializeField] private float speed; [SerializeField] private float speed;
[SerializeField] private float mouseSensitivity = 20f;
[SerializeField] private Transform playerBody;
private float _mouseX, _mouseY;
private Vector2 _moveDirection; private Vector2 _moveDirection;
private void Awake() private void Awake()
{ {
controller = GetComponent<CharacterController>(); 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) public void OnMove(InputAction.CallbackContext context)