diff --git a/Assets/_Content/Scenes/Theatre.unity b/Assets/_Content/Scenes/Theatre.unity index 38c876b0..538bd8d8 100644 --- a/Assets/_Content/Scenes/Theatre.unity +++ b/Assets/_Content/Scenes/Theatre.unity @@ -165,6 +165,40 @@ Transform: m_Children: [] m_Father: {fileID: 1451475147} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &37570376 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 37570377} + m_Layer: 0 + m_Name: Triggers + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &37570377 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 37570376} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1426382897} + - {fileID: 747625509} + - {fileID: 1155644919} + m_Father: {fileID: 1168906488} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &44782116 GameObject: m_ObjectHideFlags: 0 @@ -283,7 +317,7 @@ Transform: m_GameObject: {fileID: 50754028} serializedVersion: 2 m_LocalRotation: {x: -1.6345483e-19, y: -0.999619, z: -4.2951483e-21, w: -0.027603349} - m_LocalPosition: {x: 0.041, y: 1.5999995, z: 16.351} + m_LocalPosition: {x: 0.041, y: 1.5999995, z: -1.1490002} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -368,7 +402,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1770661310325724491, guid: ffc27657631b402499c3e000dad02251, type: 3} propertyPath: m_LocalPosition.z - value: 16.25 + value: -1.25 objectReference: {fileID: 0} - target: {fileID: 1770661310325724491, guid: ffc27657631b402499c3e000dad02251, type: 3} propertyPath: m_LocalRotation.w @@ -376,7 +410,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1770661310325724491, guid: ffc27657631b402499c3e000dad02251, type: 3} propertyPath: m_LocalRotation.x - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 1770661310325724491, guid: ffc27657631b402499c3e000dad02251, type: 3} propertyPath: m_LocalRotation.y @@ -384,7 +418,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1770661310325724491, guid: ffc27657631b402499c3e000dad02251, type: 3} propertyPath: m_LocalRotation.z - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 1770661310325724491, guid: ffc27657631b402499c3e000dad02251, type: 3} propertyPath: m_LocalEulerAnglesHint.x @@ -700,7 +734,7 @@ Transform: m_GameObject: {fileID: 249418329} serializedVersion: 2 m_LocalRotation: {x: 0.16258073, y: 0.8252836, z: -0.29678136, w: 0.4521011} - m_LocalPosition: {x: 2.77, y: 3.545, z: 23.447} + m_LocalPosition: {x: 2.77, y: 3.545, z: 5.9470005} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -813,7 +847,7 @@ GameObject: - component: {fileID: 257863902} - component: {fileID: 257863901} m_Layer: 0 - m_Name: Cube + m_Name: Stairs m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -828,7 +862,7 @@ Transform: m_GameObject: {fileID: 257863899} serializedVersion: 2 m_LocalRotation: {x: -0.19322035, y: -0, z: -0, w: 0.98115546} - m_LocalPosition: {x: 0, y: 1.2410003, z: 14.392} + m_LocalPosition: {x: 0, y: 1.2410003, z: -3.1079998} m_LocalScale: {x: 2.4757, y: 0.11168, z: 1.5526929} m_ConstrainProportionsScale: 0 m_Children: [] @@ -2044,8 +2078,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 588101097} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1.6000003, z: 16.52} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 1.6000003, z: -0.97999954} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: @@ -2078,7 +2112,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8162540767767967414, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} propertyPath: m_LocalPosition.x @@ -2380,6 +2414,55 @@ Light: m_LightUnit: 1 m_LuxAtDistance: 1 m_EnableSpotReflector: 1 +--- !u!1 &654342079 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 654342080} + - component: {fileID: 654342081} + m_Layer: 0 + m_Name: PlayerDriver + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &654342080 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 654342079} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: -5.0399017} + m_LocalScale: {x: 20.544418, y: 3.0534, z: 4.1379538} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 720343095} + - {fileID: 746559547} + m_Father: {fileID: 1168906488} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &654342081 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 654342079} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cc0335304e1f8fc4588964a0aea84656, type: 3} + m_Name: + m_EditorClassIdentifier: OctoCore.Runtime::OctoCore.OctoPlayerDrive + _references: + Target: {fileID: 720343095} + LookAt: {fileID: 746559547} --- !u!1 &685656707 GameObject: m_ObjectHideFlags: 0 @@ -2499,6 +2582,37 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!1 &720343094 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 720343095} + m_Layer: 0 + m_Name: Target + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &720343095 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 720343094} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 654342080} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &722758631 GameObject: m_ObjectHideFlags: 0 @@ -2626,6 +2740,37 @@ Light: m_LightUnit: 1 m_LuxAtDistance: 1 m_EnableSpotReflector: 1 +--- !u!1 &746559546 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 746559547} + m_Layer: 0 + m_Name: LookAt + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &746559547 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 746559546} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0.889, z: 0.923} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 654342080} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &747625508 GameObject: m_ObjectHideFlags: 0 @@ -2652,12 +2797,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 747625508} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 3, z: 16.19} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 3, z: -1.3099995} m_LocalScale: {x: 21.547, y: 3.0534, z: 0.47489} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 1168906488} + m_Father: {fileID: 37570377} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &747625510 MonoBehaviour: @@ -3573,7 +3718,7 @@ Transform: m_GameObject: {fileID: 1005038676} serializedVersion: 2 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: 17.5} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: @@ -4305,6 +4450,92 @@ MeshCollider: m_Convex: 0 m_CookingOptions: 30 m_Mesh: {fileID: 2977981768884665668, guid: 026d90e6b31bf0f47b6072ba92aef39a, type: 3} +--- !u!1 &1155644918 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1155644919} + - component: {fileID: 1155644921} + - component: {fileID: 1155644920} + m_Layer: 0 + m_Name: Trigger_GoTo + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1155644919 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1155644918} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 2.5, z: -4.61} + m_LocalScale: {x: 5.1131415, y: 3.0534, z: 5.660307} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 37570377} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1155644920 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1155644918} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5170627695bd877419928fa9ca37865d, type: 3} + m_Name: + m_EditorClassIdentifier: OctoCore.Runtime::OctoCore.Components.OctoWorldEvent + _trigger: 10 + _action: 0 + _condition: 1 + _tags: [] + _targets: [] + _onTrigger: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 654342081} + m_TargetAssemblyTypeName: OctoCore.Components.OctoPlayerDriver, OctoCore.Runtime + m_MethodName: DrivePlayer + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!65 &1155644921 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1155644918} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 1 + 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!1 &1162934183 GameObject: m_ObjectHideFlags: 0 @@ -4396,6 +4627,75 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1162934183} m_Mesh: {fileID: 2112596279228391150, guid: 026d90e6b31bf0f47b6072ba92aef39a, type: 3} +--- !u!1001 &1167326761 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 3452915509921429875, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6989128982853398086, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_RenderPostProcessing + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8162540767767967414, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_Name + value: OctoPlayerFP (1) + objectReference: {fileID: 0} + - target: {fileID: 8162540767767967414, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalPosition.x + value: -7.5916495 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalPosition.y + value: 1.6 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalPosition.z + value: 21.919136 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalRotation.w + value: 0.40772554 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalRotation.y + value: 0.91310453 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 131.876 + objectReference: {fileID: 0} + - target: {fileID: 8725966219179855439, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: bfb9a06a57603714ca245d62fcd622f1, type: 3} --- !u!1 &1168906487 GameObject: m_ObjectHideFlags: 0 @@ -4425,8 +4725,8 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 1426382897} - - {fileID: 747625509} + - {fileID: 654342080} + - {fileID: 37570377} - {fileID: 588101098} - {fileID: 257863900} m_Father: {fileID: 1005038677} @@ -5288,12 +5588,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1426382896} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 3, z: 19.55} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 3, z: 2.39} m_LocalScale: {x: 21.547, y: 3.0534, z: 0.47489} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 1168906488} + m_Father: {fileID: 37570377} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1426382898 MonoBehaviour: @@ -6082,7 +6382,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1698321436} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: a3c782d1f27ea224fa07abf16ac61117, type: 3} m_Name: @@ -14090,6 +14390,7 @@ SceneRoots: - {fileID: 235456880} - {fileID: 1380886451} - {fileID: 642044301} + - {fileID: 1167326761} - {fileID: 2011606366} - {fileID: 1107210254} - {fileID: 923492554} diff --git a/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayer.cs b/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayer.cs index c9279c2b..d935890a 100644 --- a/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayer.cs +++ b/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayer.cs @@ -1,6 +1,8 @@ using OctoCore.Inputs; +using System.Linq; using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.UIElements; namespace OctoCore.Components { @@ -19,6 +21,13 @@ namespace OctoCore.Components public bool IsRunning; public float Yaw; public float Pitch; + + [Space(10)] + + public bool IsDriven; + [Range(0, 1)] public float DriventIntensity; + public Transform DriveTarget; + public Transform DriveLookAt; } [System.Serializable] @@ -129,6 +138,61 @@ namespace OctoCore.Components } void Update() + { + HandleFocus(); + HandleMovement(); + } + + public void Teleport(Vector3 position, Quaternion rotation) + { + State.IsPaused = _jumpInput = _jumpping = _runInput = false; + _runInertia = _jumpLerp = _jumpTime = _jumpAltitude = 0; + _moveInput = _lookInput = Vector2.zero; + _moveInertia = _moveDirection = Vector3.zero; + State.Yaw = rotation.eulerAngles.y; + State.Pitch = 0; + + if (_references.Controller) + _references.Controller.enabled = false; + + transform.position = position; + transform.rotation = rotation; + + if (_references.Controller) + _references.Controller.enabled = true; + } + + public void Pause(bool pause) + { + State.IsPaused = pause; + + if (OctoCore.Instance) + OctoCore.Instance.UI.SetCursor(); + } + + public void Drive(Transform target, Transform lookAt) + { + State.DriveTarget = target; + State.DriveLookAt = lookAt; + State.IsDriven = true; + } + + public void ReleaseDrive() + { + State.IsDriven = false; + State.DriveTarget = null; + State.DriveLookAt = null; + } + + public void SetYaw(float yaw) { State.Yaw = yaw; } + public void SetPitch(float pitch) { State.Yaw = pitch; } + + private void Move(Vector2 value) { _moveInput = value; } + private void Look(Vector2 value) { _lookInput = value; } + private void Run() { _runInput = true; } + private void Jump() { _jumpInput = true; } + + private void HandleFocus() { bool escapePressed = false; bool mouseClicked = false; @@ -167,8 +231,10 @@ namespace OctoCore.Components if (!_wasPausedBeforeUnfocuss) Pause(false); } + } - + private void HandleMovement() + { _moveInput = (State.IsPaused || !State.IsFocussed) ? Vector2.zero : Vector2.ClampMagnitude(_moveInput, 1); Camera cam = (_firstPerson.Camera && _firstPerson.Camera.enabled && _firstPerson.Camera.gameObject.activeInHierarchy) ? _firstPerson.Camera : Camera.main; @@ -193,6 +259,22 @@ namespace OctoCore.Components move = camRight * move.x + camForward * move.z; } + if (State.IsDriven) + { + State.DriventIntensity = Mathf.Clamp01(State.DriventIntensity + move.magnitude * t * 1); + + Vector3 driveDir = State.DriveTarget.position - transform.position; + + float driveAtten = 1 - Mathf.Clamp01(driveDir.magnitude); + + Vector3 driveMove = driveDir; + driveMove.y = 0; + driveMove = driveMove.normalized * move.magnitude; + driveMove = Vector3.Lerp(driveMove, Vector3.zero, driveAtten); + + move = Vector3.Lerp(move, driveMove, State.DriventIntensity); + } + float deltaSmooth = t * (accelerating ? 30 : 15); _moveDirection = Vector3.Lerp(_moveDirection, move, deltaSmooth * 1.5f); @@ -205,7 +287,7 @@ namespace OctoCore.Components State.IsRunning = _runInertia > .1f; Vector3 moveDelta = _moveInertia * t * Mathf.Lerp(_settings.WalkSpeed, _settings.RunSpeed, _runInertia); - + if (isGrounded && _jumpInput && !_jumpping) { _jumpInput = false; @@ -231,11 +313,11 @@ namespace OctoCore.Components { float x = _jumpLerp; x = x * 2 - 1; - + float y; if (x < 0) y = Mathf.Sqrt(1f - x * x); else y = Mathf.Cos(x * .5f * Mathf.PI); - + y = _jumpAltitude + y * _settings.JumpHeight; jumpOffset = y - transform.position.y; @@ -267,8 +349,31 @@ namespace OctoCore.Components State.Yaw += mouseX; State.Pitch = Mathf.Clamp(State.Pitch + mouseY, _firstPerson.MinPitch, _firstPerson.MaxPitch); - transform.rotation = Quaternion.Euler(0, State.Yaw, 0); - cam.transform.localRotation = Quaternion.Euler(State.Pitch, 0, 0); + if (State.IsDriven) + { + Vector3 lookAt = State.DriveLookAt.position - _firstPerson.Camera.transform.position; + lookAt = lookAt.normalized; + + Vector3 playerPos2D = transform.position; + Vector3 targetPos2D = State.DriveTarget.position; + playerPos2D.y = targetPos2D.y = 0; + + float yaw = Mathf.Atan2(lookAt.x, lookAt.z) * Mathf.Rad2Deg; + float pitch = Mathf.Asin(-lookAt.y) * Mathf.Rad2Deg; + + float lerp = 1 - Mathf.Clamp01(Vector3.Distance(playerPos2D, targetPos2D) / 2); + float yawRange = Mathf.Lerp(180, 0, lerp); + float pitchRange = Mathf.Lerp(90, 0, lerp); + + State.Yaw = yaw + Mathf.Clamp(Mathf.DeltaAngle(yaw, State.Yaw), -yawRange, yawRange); + State.Pitch = pitch + Mathf.Clamp(Mathf.DeltaAngle(pitch, State.Pitch), -pitchRange, pitchRange); + } + + Quaternion YawRot = Quaternion.Euler(0, State.Yaw, 0); + Quaternion PitchRot = Quaternion.Euler(State.Pitch, 0, 0); + + transform.rotation = YawRot; + cam.transform.localRotation = PitchRot; } break; @@ -296,41 +401,6 @@ namespace OctoCore.Components _runInput = false; } - public void Teleport(Vector3 position, Quaternion rotation) - { - State.IsPaused = _jumpInput = _jumpping = _runInput = false; - _runInertia = _jumpLerp = _jumpTime = _jumpAltitude = 0; - _moveInput = _lookInput = Vector2.zero; - _moveInertia = _moveDirection = Vector3.zero; - State.Yaw = rotation.eulerAngles.y; - State.Pitch = 0; - - if (_references.Controller) - _references.Controller.enabled = false; - - transform.position = position; - transform.rotation = rotation; - - if (_references.Controller) - _references.Controller.enabled = true; - } - - public void Pause(bool pause) - { - State.IsPaused = pause; - - if (OctoCore.Instance) - OctoCore.Instance.UI.SetCursor(); - } - - public void SetYaw(float yaw) { State.Yaw = yaw; } - public void SetPitch(float pitch) { State.Yaw = pitch; } - - private void Move(Vector2 value) { _moveInput = value; } - private void Look(Vector2 value) { _lookInput = value; } - private void Run() { _runInput = true; } - private void Jump() { _jumpInput = true; } - private void SetMode() { switch (_settings.Mode) diff --git a/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayerDriver.cs b/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayerDriver.cs new file mode 100644 index 00000000..da979091 --- /dev/null +++ b/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayerDriver.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +namespace OctoCore.Components +{ + public class OctoPlayerDriver : MonoBehaviour + { + [System.Serializable] + public class References + { + public Transform Target; + public Transform LookAt; + } + + [SerializeField] private References _references; + + void Start() + { + + } + + void Update() + { + + } + + public void DrivePlayer() + { + OctoPlayer.Instance.Drive(_references.Target, _references.LookAt); + } + } +} diff --git a/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayerDriver.cs.meta b/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayerDriver.cs.meta new file mode 100644 index 00000000..a255646f --- /dev/null +++ b/Packages/OctoCore/Runtime/Scripts/Components/OctoPlayerDriver.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cc0335304e1f8fc4588964a0aea84656 \ No newline at end of file