5 Commits

Author SHA1 Message Date
Chris
236f9ea5df feat: lock-on added, rotation reworked 2025-07-08 19:26:09 -04:00
Chris
94c5a72049 added: early version of lock on cancel 2025-07-03 14:31:59 -04:00
Chris
15bf8e9b9d Merge remote-tracking branch 'origin/main' into player/rotation-and-lock-on
# Conflicts:
#	Assets/Scenes/SampleScene.unity
#	Assets/Scripts/Core/LockOnManager.cs
2025-03-20 16:46:13 -04:00
Chris
127df3d878 added: lock on switching 2025-03-20 16:45:29 -04:00
Chris
6b4ddb101f added: lock on target graphic 2025-03-20 15:28:15 -04:00
9 changed files with 389 additions and 122 deletions

View File

@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f945e777233a59f4aba40aeca29093a6, type: 3}
m_Name: PlayerLocomotionFSM
m_EditorClassIdentifier:
_serializedGraph: '{"type":"NodeCanvas.StateMachines.FSM","nodes":[{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":10.0},"moveDirection":{"_name":"groundMoveDirection","_targetVariableID":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6"},"$type":"NodeCanvas.Tasks.Actions.CalculateGroundedLocomotion"},{"valueA":{"_name":"rotationSpeed","_targetVariableID":"d888730f-97df-4288-bb99-1f6c8a34a7c5"},"valueB":{"_value":0.3},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_repeatStateActions":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_position":{"x":559.9924,"y":711.7622},"$type":"NodeCanvas.StateMachines.ActionState","$id":"0"},{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":15.0},"moveDirection":{"_name":"groundMoveDirection","_targetVariableID":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6"},"$type":"NodeCanvas.Tasks.Actions.CalculateGroundedLocomotion"},{"valueA":{"_name":"rotationSpeed","_targetVariableID":"d888730f-97df-4288-bb99-1f6c8a34a7c5"},"valueB":{"_value":0.2},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_repeatStateActions":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_position":{"x":874.288,"y":572.152},"$type":"NodeCanvas.StateMachines.ActionState","$id":"1"},{"_position":{"x":430.6569,"y":381.1322},"$type":"NodeCanvas.StateMachines.AnyState","$id":"2"},{"_position":{"x":465.0,"y":561.0},"$type":"NodeCanvas.StateMachines.EmptyState","$id":"3"}],"connections":[{"_condition":{"actionName":{"_value":"Sprint"},"actionValue":{"_value":""},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"desiredVector3":{"_value":{"z":1.0}},"tolerance":{"_value":0.5},"negate":{},"$type":"NodeCanvas.Tasks.Conditions.GetMovementInputDotProduct"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"0"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"321e55c7-f93e-4667-a0dc-559eb61c6898"},"valueB":{},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"2"},"_targetNode":{"$ref":"3"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"321e55c7-f93e-4667-a0dc-559eb61c6898"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"3"},"_targetNode":{"$ref":"0"},"$type":"NodeCanvas.StateMachines.FSMConnection"}],"canvasGroups":[],"localBlackboard":{"_variables":{"isGrounded":{"_propertyPath":"UnityEngine.CharacterController.isGrounded","_name":"isGrounded","_id":"321e55c7-f93e-4667-a0dc-559eb61c6898","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
_serializedGraph: '{"type":"NodeCanvas.StateMachines.FSM","nodes":[{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":10.0},"moveDirection":{"_name":"groundMoveDirection","_targetVariableID":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6"},"$type":"NodeCanvas.Tasks.Actions.CalculateGroundedLocomotion"},{"valueA":{"_name":"rotationSpeed","_targetVariableID":"d888730f-97df-4288-bb99-1f6c8a34a7c5"},"valueB":{"_value":0.3},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_repeatStateActions":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_position":{"x":559.9924,"y":711.7622},"$type":"NodeCanvas.StateMachines.ActionState","$id":"0"},{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":15.0},"moveDirection":{"_name":"groundMoveDirection","_targetVariableID":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6"},"$type":"NodeCanvas.Tasks.Actions.CalculateGroundedLocomotion"},{"valueA":{"_name":"rotationSpeed","_targetVariableID":"d888730f-97df-4288-bb99-1f6c8a34a7c5"},"valueB":{"_value":0.2},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_repeatStateActions":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_position":{"x":1161.288,"y":522.152},"$type":"NodeCanvas.StateMachines.ActionState","$id":"1"},{"_position":{"x":430.6569,"y":381.1322},"$type":"NodeCanvas.StateMachines.AnyState","$id":"2"},{"_position":{"x":465.0,"y":561.0},"$type":"NodeCanvas.StateMachines.EmptyState","$id":"3"}],"connections":[{"_condition":{"actionName":{"_value":"Sprint"},"actionValue":{"_value":""},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"desiredVector3":{"_value":{"z":1.0}},"tolerance":{"_value":0.5},"negate":{},"$type":"NodeCanvas.Tasks.Conditions.GetMovementInputDotProduct"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"0"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"321e55c7-f93e-4667-a0dc-559eb61c6898"},"valueB":{},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"2"},"_targetNode":{"$ref":"3"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"321e55c7-f93e-4667-a0dc-559eb61c6898"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"3"},"_targetNode":{"$ref":"0"},"$type":"NodeCanvas.StateMachines.FSMConnection"}],"canvasGroups":[],"localBlackboard":{"_variables":{"isGrounded":{"_propertyPath":"UnityEngine.CharacterController.isGrounded","_name":"isGrounded","_id":"321e55c7-f93e-4667-a0dc-559eb61c6898","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"groundMoveDirection":{"_name":"groundMoveDirection","_id":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6","_isPublic":true,"$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"rotationSpeed":{"_name":"rotationSpeed","_id":"d888730f-97df-4288-bb99-1f6c8a34a7c5","_isPublic":true,"$type":"NodeCanvas.Framework.Variable`1[[System.Single,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}}}}'
@@ -21,7 +21,7 @@ MonoBehaviour:
_version: 3.31
_category:
_comments:
_translation: {x: 129, y: -157}
_zoomFactor: 0.9962392
_translation: {x: 1, y: -175}
_zoomFactor: 0.9967056
_haltSerialization: 0
_externalSerializationFile: {fileID: 0}

View File

@@ -40,6 +40,24 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Lock-On",
"type": "Button",
"id": "4c8aaf72-5298-4d47-b75f-90070301913b",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Cancel Lock-On",
"type": "Button",
"id": "f38f6ac6-41ce-416a-b47c-f948d0cde68a",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
@@ -141,6 +159,83 @@
"action": "Sprint",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "0aec47c4-b519-4001-9408-a49abe218bd8",
"path": "",
"interactions": "",
"processors": "",
"groups": "",
"action": "Lock-On",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "c9d67b81-b640-4a64-9b31-f92c927c8345",
"path": "<Gamepad>/rightStickPress",
"interactions": "",
"processors": "",
"groups": ";Controller",
"action": "Lock-On",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "89e90b8f-c830-4d10-9046-c1db1ef970d0",
"path": "",
"interactions": "",
"processors": "",
"groups": "",
"action": "Cancel Lock-On",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "One Modifier",
"id": "cd93e290-6f16-49c1-af36-9d3eaedeb8a2",
"path": "OneModifier",
"interactions": "",
"processors": "",
"groups": "",
"action": "Cancel Lock-On",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "modifier",
"id": "8713a052-f2c4-439a-acae-f845a5654819",
"path": "",
"interactions": "",
"processors": "",
"groups": "",
"action": "Cancel Lock-On",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "binding",
"id": "013863ac-050d-4d7f-a36c-bce06827ad17",
"path": "",
"interactions": "",
"processors": "",
"groups": "",
"action": "Cancel Lock-On",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "84c3f849-8d7f-40ea-8c6c-4b5af0d9addd",
"path": "<Gamepad>/rightStickPress",
"interactions": "Hold",
"processors": "",
"groups": ";Controller",
"action": "Cancel Lock-On",
"isComposite": false,
"isPartOfComposite": false
}
]
}

View File

@@ -2447,12 +2447,12 @@ GameObject:
- component: {fileID: 263093400}
- component: {fileID: 263093404}
m_Layer: 0
m_Name: Lock-On Target
m_Name: 'Lock-On Target: Open'
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!136 &263093400
CapsuleCollider:
m_ObjectHideFlags: 0
@@ -2644,8 +2644,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 330585543}
serializedVersion: 2
m_LocalRotation: {x: 0.015995976, y: -0.067584075, z: 0.0010836906, w: 0.99758476}
m_LocalPosition: {x: 1.5039132, y: 2.1421127, z: -6.8609486}
m_LocalRotation: {x: 0.11558351, y: 0.00000003563248, z: -0.000000004146316, w: 0.99329776}
m_LocalPosition: {x: 1.503913, y: 2.0657892, z: -6.8609486}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -2837,7 +2837,7 @@ GameObject:
- component: {fileID: 402424906}
- component: {fileID: 402424905}
- component: {fileID: 402424907}
- component: {fileID: 402424909}
- component: {fileID: 402424911}
- component: {fileID: 402424910}
- component: {fileID: 402424908}
m_Layer: 0
@@ -2898,8 +2898,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 402424904}
serializedVersion: 2
m_LocalRotation: {x: 0.015995974, y: -0.06758407, z: 0.0010836904, w: 0.9975848}
m_LocalPosition: {x: 1.5039132, y: 2.1421127, z: -6.8609486}
m_LocalRotation: {x: 0.115583494, y: 0.000000035632475, z: -0.000000004146315, w: 0.99329776}
m_LocalPosition: {x: 1.503913, y: 2.0657892, z: -6.8609486}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -2919,7 +2919,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
TargetOffset: {x: 0, y: 0, z: 0}
TrackerSettings:
BindingMode: 0
BindingMode: 5
PositionDamping: {x: 1, y: 1, z: 1}
AngularDampingMode: 0
RotationDamping: {x: 0, y: 0, z: 0}
@@ -2929,7 +2929,7 @@ MonoBehaviour:
Orbits:
Top:
Radius: 5.12
Height: 6.55
Height: 5.25
Center:
Radius: 5.53
Height: 2.7
@@ -2937,16 +2937,16 @@ MonoBehaviour:
Radius: 4.18
Height: 1.89
SplineCurvature: 0
RecenteringTarget: 0
RecenteringTarget: 2
HorizontalAxis:
Value: 0
Center: 0
Center: 41.584503
Range: {x: -180, y: 180}
Wrap: 1
Recentering:
Enabled: 0
Wait: 1
Time: 2
Wait: 0
Time: 60
Restrictions: 0
VerticalAxis:
Value: 20
@@ -2987,10 +2987,10 @@ MonoBehaviour:
Controllers:
- Name: Look Orbit X
Owner: {fileID: 402424907}
Enabled: 0
Enabled: 1
Input:
InputAction: {fileID: 6185001796860367008, guid: 652c4cc5d47d8de45a54e21abc9d8d1a, type: 3}
Gain: 1
Gain: 200
LegacyInput:
LegacyGain: 200
CancelDeltaTime: 0
@@ -3026,35 +3026,6 @@ MonoBehaviour:
DecelTime: 0
PlayerIndex: -1
AutoEnableInputs: 1
--- !u!114 &402424909
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 402424904}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f38bda98361e1de48a4ca2bd86ea3c17, type: 3}
m_Name:
m_EditorClassIdentifier:
Composition:
ScreenPosition: {x: 0, y: 0}
DeadZone:
Enabled: 0
Size: {x: 0.2, y: 0.2}
HardLimits:
Enabled: 0
Size: {x: 0.8, y: 0.8}
Offset: {x: 0, y: 0}
CenterOnActivate: 1
TargetOffset: {x: 0.57, y: 1.92, z: 0}
Damping: {x: 0, y: 0.1}
Lookahead:
Enabled: 1
Time: 0
Smoothing: 0
IgnoreY: 0
--- !u!114 &402424910
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -3076,6 +3047,35 @@ MonoBehaviour:
FovRange: {x: 1, y: 100}
DollyRange: {x: -100, y: 100}
OrthoSizeRange: {x: 1, y: 1000}
--- !u!114 &402424911
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 402424904}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f38bda98361e1de48a4ca2bd86ea3c17, type: 3}
m_Name:
m_EditorClassIdentifier:
Composition:
ScreenPosition: {x: 0, y: 0.15}
DeadZone:
Enabled: 0
Size: {x: 0.2, y: 0.2}
HardLimits:
Enabled: 0
Size: {x: 0.8, y: 0.8}
Offset: {x: 0, y: 0}
CenterOnActivate: 1
TargetOffset: {x: 0, y: 0, z: 0}
Damping: {x: 0.5, y: 0.5}
Lookahead:
Enabled: 0
Time: 0
Smoothing: 0
IgnoreY: 0
--- !u!1 &410087039
GameObject:
m_ObjectHideFlags: 0
@@ -3398,9 +3398,6 @@ MonoBehaviour:
- Object: {fileID: 1992890473}
Weight: 1
Radius: 3.64
- Object: {fileID: 1379573506}
Weight: 0.15
Radius: 3.64
m_LegacyTargets: []
--- !u!4 &615613681
Transform:
@@ -3411,7 +3408,7 @@ Transform:
m_GameObject: {fileID: 615613679}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 1.5039132, y: -0.81913054, z: -1.296337}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -5299,7 +5296,7 @@ GameObject:
- component: {fileID: 1379573503}
- component: {fileID: 1379573507}
m_Layer: 0
m_Name: Lock-On Target
m_Name: 'Lock-On Target: Platform'
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -5422,12 +5419,12 @@ GameObject:
- component: {fileID: 1505662771}
- component: {fileID: 1505662775}
m_Layer: 0
m_Name: Lock-On Target
m_Name: 'Lock-On Target: Floor'
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!136 &1505662771
CapsuleCollider:
m_ObjectHideFlags: 0
@@ -6153,7 +6150,7 @@ Transform:
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 9.9538, y: 9.9538, z: 9.9538}
m_LocalScale: {x: 168.92595, y: 168.92595, z: 168.92595}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 204093123}
@@ -6716,10 +6713,10 @@ MonoBehaviour:
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}]},"foldEnter":true,"foldExit":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Ground
Idle","_position":{"x":449.1072,"y":171.9887},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"0"},{"_onEnterList":{"executionMode":1,"actions":[{"valueA":{"_name":"airJumpsRemaining","_targetVariableID":"23f0ddc0-c4e8-462f-a7e0-fdd8e818d08d"},"Operation":2,"valueB":{"_value":1},"$type":"NodeCanvas.Tasks.Actions.SetInt"}]},"_onUpdateList":{"executionMode":1,"actions":[{"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"groundMoveDirection":{"_name":"groundMoveDirection","_targetVariableID":"765d24b4-452d-4531-9fce-6cef7ba39634"},"$type":"NodeCanvas.Tasks.Actions.CalculateAirMovement"}]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"foldUpdate":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Airborn
(Actionable)","_position":{"x":607.037,"y":-147.5533},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"1"},{"_onEnterList":{"executionMode":1,"actions":[{"jumpStrength":{"_value":18.0},"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"standStillJumpStrength":{},"jumpPower":{"_name":"jumpPower","_targetVariableID":"9a82efee-e317-423c-ad6e-5ef7e6145396"},"currentVelocityInheritence":{"_value":0.2},"directionalForce":{"_value":{"y":1.0,"z":0.3}},"directionalForceStrength":{"_value":1.0},"$type":"NodeCanvas.Tasks.Actions.AddJump"},{"valueA":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"valueB":{},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_onUpdateList":{"executionMode":1,"actions":[]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Wall
Climb Jump","_position":{"x":1082.0,"y":-276.0},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"2"},{"_onEnterList":{"executionMode":1,"actions":[{"jumpStrength":{},"airMoveDirection":{},"standStillJumpStrength":{},"jumpPower":{},"currentVelocityInheritence":{},"directionalForce":{},"directionalForceStrength":{},"$type":"NodeCanvas.Tasks.Actions.AddJump"},{"valueA":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"valueB":{},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_onUpdateList":{"executionMode":1,"actions":[]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Wall
Climb Jump","_position":{"x":1065.998,"y":-269.9991},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"2"},{"_onEnterList":{"executionMode":1,"actions":[{"jumpStrength":{},"airMoveDirection":{},"standStillJumpStrength":{},"jumpPower":{},"currentVelocityInheritence":{},"directionalForce":{},"directionalForceStrength":{},"$type":"NodeCanvas.Tasks.Actions.AddJump"},{"valueA":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"valueB":{},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_onUpdateList":{"executionMode":1,"actions":[]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Wall
Jump","_position":{"x":868.4374,"y":-418.9596},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"3"},{"_onEnterList":{"executionMode":1,"actions":[{"jumpStrength":{"_value":12.0},"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"standStillJumpStrength":{"_value":1.0},"jumpPower":{"_name":"jumpPower","_targetVariableID":"9a82efee-e317-423c-ad6e-5ef7e6145396"},"currentVelocityInheritence":{"_value":1.0},"directionalForce":{},"directionalForceStrength":{},"$type":"NodeCanvas.Tasks.Actions.AddJump"},{"valueA":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"valueB":{},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_onUpdateList":{"executionMode":1,"actions":[]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Standard
Jump","_position":{"x":831.2836,"y":45.40904},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"4"},{"_onEnterList":{"executionMode":1,"actions":[]},"_onUpdateList":{"executionMode":1,"actions":[{"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"groundMoveDirection":{"_name":"groundMoveDirection","_targetVariableID":"765d24b4-452d-4531-9fce-6cef7ba39634"},"$type":"NodeCanvas.Tasks.Actions.CalculateAirMovement"}]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"foldUpdate":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Airborn","_position":{"x":213.7761,"y":-7.08618},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"5"},{"_onEnterList":{"executionMode":1,"actions":[{"jumpStrength":{"_value":10.0},"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"standStillJumpStrength":{},"jumpPower":{"_name":"jumpPower","_targetVariableID":"9a82efee-e317-423c-ad6e-5ef7e6145396"},"currentVelocityInheritence":{"_value":0.3},"directionalForce":{"_value":{"x":1.0,"z":1.0}},"directionalForceStrength":{"_value":10.0},"$type":"NodeCanvas.Tasks.Actions.AddJump"},{"valueA":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"valueB":{},"$type":"NodeCanvas.Tasks.Actions.SetFloat"}]},"_onUpdateList":{"executionMode":1,"actions":[]},"_onExitList":{"executionMode":1,"actions":[]},"foldEnter":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_name":"Wall
Jump","_position":{"x":328.7507,"y":-415.5261},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"6"},{"_subFSM":{"_value":1},"_variablesMap":[{"_targetSubGraphVariableID":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6","_canRead":true,"_canWrite":true,"_type":"UnityEngine.Vector3","_name":"groundMoveDirection","_targetVariableID":"765d24b4-452d-4531-9fce-6cef7ba39634"},{"_targetSubGraphVariableID":"d888730f-97df-4288-bb99-1f6c8a34a7c5","_canRead":true,"_canWrite":true,"_type":"System.Single","_name":"rotationSpeed","_targetVariableID":"3a7d1c7c-8fb6-4a99-b25a-b434b62d4611"}],"_position":{"x":-51.59897,"y":405.3138},"$type":"NodeCanvas.StateMachines.ConcurrentSubFSM"},{"_conditionList":{"conditions":[{"_invert":true,"$type":"NodeCanvas.Tasks.Conditions.DebugCondition"}]},"_actionList":{"executionMode":1,"actions":[{"groundMoveDirection":{"_name":"groundMoveDirection","_targetVariableID":"765d24b4-452d-4531-9fce-6cef7ba39634"},"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"gravityAcceleration":{"_value":1.0},"gravityMax":{"_value":8.0},"jumpPower":{"_name":"jumpPower","_targetVariableID":"9a82efee-e317-423c-ad6e-5ef7e6145396"},"jumpPowerDecay":{"_value":2.0},"rotationSpeed":{"_name":"rotationSpeed","_targetVariableID":"3a7d1c7c-8fb6-4a99-b25a-b434b62d4611"},"rotationSmoothing":{"_value":1.0},"gravityPower":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"$type":"NodeCanvas.Tasks.Actions.ProcessMovement"}]},"_position":{"x":-53.13061,"y":270.8315},"$type":"NodeCanvas.StateMachines.OnFSMEnter"}],"connections":[{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"619300a4-be8b-4ad4-ba2a-978468094ba2"},"valueB":{},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"actionName":{"_value":"Jump"},"actionValue":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"conditions":[{"eventName":{"_value":"ForwardRay"},"value":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckEventValue`1[[System.Boolean,
Jump","_position":{"x":328.7507,"y":-415.5261},"$type":"NodeCanvas.StateMachines.SuperActionState","$id":"6"},{"_subFSM":{"_value":1},"_variablesMap":[{"_targetSubGraphVariableID":"16ae5ce4-097a-4c21-94a5-2c5d9ce73eb6","_canRead":true,"_canWrite":true,"_type":"UnityEngine.Vector3","_name":"groundMoveDirection","_targetVariableID":"765d24b4-452d-4531-9fce-6cef7ba39634"},{"_targetSubGraphVariableID":"d888730f-97df-4288-bb99-1f6c8a34a7c5","_canRead":true,"_canWrite":true,"_type":"System.Single","_name":"rotationSpeed","_targetVariableID":"3a7d1c7c-8fb6-4a99-b25a-b434b62d4611"}],"_position":{"x":-50.62204,"y":454.3138},"$type":"NodeCanvas.StateMachines.ConcurrentSubFSM"},{"_conditionList":{"conditions":[{"_invert":true,"$type":"NodeCanvas.Tasks.Conditions.DebugCondition"}]},"_actionList":{"executionMode":1,"actions":[{"groundMoveDirection":{"_name":"groundMoveDirection","_targetVariableID":"765d24b4-452d-4531-9fce-6cef7ba39634"},"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"8f5f926f-618d-4bcb-87eb-0bcd02e405a2"},"gravityAcceleration":{"_value":1.0},"gravityMax":{"_value":8.0},"jumpPower":{"_name":"jumpPower","_targetVariableID":"9a82efee-e317-423c-ad6e-5ef7e6145396"},"jumpPowerDecay":{"_value":2.0},"playerFacingDirection":1,"rotationSpeed":{"_name":"rotationSpeed","_targetVariableID":"3a7d1c7c-8fb6-4a99-b25a-b434b62d4611"},"rotationSmoothing":{"_value":1.0},"gravityPower":{"_name":"gravityPower","_targetVariableID":"2221dc20-d9b3-4781-bd23-0b2038a7ff5e"},"$type":"NodeCanvas.Tasks.Actions.ProcessMovement"}]},"_position":{"x":-53.13062,"y":301.5233},"$type":"NodeCanvas.StateMachines.OnFSMEnter"}],"connections":[{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"619300a4-be8b-4ad4-ba2a-978468094ba2"},"valueB":{},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"actionName":{"_value":"Jump"},"actionValue":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"conditions":[{"eventName":{"_value":"ForwardRay"},"value":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckEventValue`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},{"actionName":{"_value":"Jump"},"actionValue":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"}],"$type":"NodeCanvas.Framework.ConditionList"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"2"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"conditions":[{"actionName":{"_value":"Jump"},"actionValue":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},{"eventName":{"_value":"RightRay"},"$type":"NodeCanvas.Tasks.Conditions.CheckEvent"}],"$type":"NodeCanvas.Framework.ConditionList"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"3"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"actionName":{"_value":"Jump"},"actionValue":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"airJumpsRemaining","_targetVariableID":"23f0ddc0-c4e8-462f-a7e0-fdd8e818d08d"},"valueB":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInt"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"5"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"619300a4-be8b-4ad4-ba2a-978468094ba2"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"0"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"conditions":[{"actionName":{"_value":"Jump"},"actionValue":{},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},{"eventName":{"_value":"LeftRay"},"$type":"NodeCanvas.Tasks.Conditions.CheckEvent"}],"$type":"NodeCanvas.Framework.ConditionList"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"6"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_sourceNode":{"$ref":"2"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_sourceNode":{"$ref":"3"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_sourceNode":{"$ref":"4"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"619300a4-be8b-4ad4-ba2a-978468094ba2"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"5"},"_targetNode":{"$ref":"0"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_sourceNode":{"$ref":"6"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"}],"canvasGroups":[],"localBlackboard":{"_variables":{"isGrounded":{"_propertyPath":"UnityEngine.CharacterController.isGrounded","_name":"isGrounded","_id":"619300a4-be8b-4ad4-ba2a-978468094ba2","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"forwardRay":{"_propertyPath":"PlayerMovement.forwardRay","_name":"forwardRay","_id":"a2506ca5-1b47-4820-9921-3ff4ecc18564","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.RaycastHit,
UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"airJumpsRemaining":{"_name":"airJumpsRemaining","_id":"23f0ddc0-c4e8-462f-a7e0-fdd8e818d08d","$type":"NodeCanvas.Framework.Variable`1[[System.Int32,
@@ -6736,7 +6733,7 @@ MonoBehaviour:
_version: 3.31
_category:
_comments:
_translation: {x: 601, y: 245}
_translation: {x: 134, y: 549}
_zoomFactor: 1
_firstActivation: 0
_enableAction: 0
@@ -6758,8 +6755,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 092c74123418b7a4482fc45aa5870077, type: 3}
m_Name:
m_EditorClassIdentifier:
lockOnRange: 40
lockOnMaxAngle: 70
lockonGameObject: {fileID: 0}
lockonTarget:
Object: {fileID: 0}
Weight: 1
Radius: 0.5
targetGroup: {fileID: 615613680}
lockOnTargets:
- {fileID: 1505662770}
- {fileID: 1379573502}
- {fileID: 263093399}
lockOnDocument: {fileID: 1223043171}
lockOnTarget: {fileID: 1379573502}
--- !u!1 &2024357130
GameObject:
m_ObjectHideFlags: 0

View File

@@ -2,7 +2,6 @@ using UnityEngine;
public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
public float lockonTargetRadius{ get; set; } = 1f;
public Renderer thisRenderer { get; }
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start(){
@@ -10,6 +9,6 @@ public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
}
void Update(){
Debug.Log((this as ILockOnTarget).GetReticlePosition());
}
}

View File

@@ -1,9 +1,18 @@
using System;
using System.Collections;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Services;
using Unity.Cinemachine;
using Unity.Mathematics;
using UnityEngine;
public enum PlayerFacingDirection{
Target = 0,
Movement,
MatchCamera
}
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Movement")]
@@ -18,19 +27,36 @@ namespace NodeCanvas.Tasks.Actions {
public BBParameter<float> jumpPower;
public BBParameter<float> jumpPowerDecay;
// Rotation
public PlayerFacingDirection playerFacingDirection;
[ShowIf("playerFacingDirection", 0)]
public Vector3 rotationTargetPosition;
public BBParameter<float> rotationSpeed = 5f;
public BBParameter<float> rotationSmoothing;
private float currentRotSpeed;
private Vector3 rotationNoY;
private float lastLookMagnitude;
private Quaternion targetRotation;
// References
private PlayerControls controls;
public BBParameter<float> gravityPower;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit() {
// Append the late update method to actually happen on late update
MonoManager.current.onLateUpdate += LateUpdate;
// What
currentRotSpeed = rotationSpeed.value;
// Reference to controls
controls = agent.GetComponent<PlayerControls>();
return null;
}
@@ -43,67 +69,63 @@ namespace NodeCanvas.Tasks.Actions {
//Called once per frame while the action is active.
protected override void OnUpdate(){
// Get input values
Vector2 rawLookInputVector3 = agent.GetComponent<PlayerControls>().rawLookInput;
Vector2 rawMoveInputVector3 = agent.GetComponent<PlayerControls>().rawMoveInput;
// Accelerate gravity
gravityPower.value += gravityAcceleration.value * Time.deltaTime;
gravityPower.value = Mathf.Min(gravityPower.value, gravityMax.value);
// Calculate rotation speed
currentRotSpeed = Mathf.Lerp(currentRotSpeed, rotationSpeed.value, rotationSmoothing.value * Time.deltaTime);
// Process input rotation
agent.transform.Rotate(new Vector3(0, agent.GetComponent<PlayerControls>().rawLookInput.x * rotationSpeed.value * 360f * Time.deltaTime)); // *360 to account for a full circle taking a long ass time
// Process movement rotation
if (agent.isGrounded){
// Quaternion cameraRotNoY = Quaternion.Euler(0f, Camera.main.transform.rotation.eulerAngles.y , 0f);
// agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, Quaternion.LookRotation(agent.transform.position + groundMoveDirection.value), 10f * Time.deltaTime);
} else {
// rotationNoY = airMoveDirection.value;
// rotationNoY.x = 0f;
// rotationNoY.z = 0f;
// agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, Quaternion.Euler(rotationNoY), 5f * Time.deltaTime);
switch (playerFacingDirection) {
case PlayerFacingDirection.Target:
// Set rotation to just the direction of the target
targetRotation = Quaternion.LookRotation((agent.transform.position.DirectionTo(rotationTargetPosition)).Flatten(null, 0, null));
break;
case PlayerFacingDirection.Movement:
// Check magnitude to avoid the "Look rotation viewing vector is zero" debug
if (controls.rawMoveInput.magnitude == 0) { break; }
// Set desired rotation to input direction, with respect to camera rotation
targetRotation = Quaternion.LookRotation(new Vector3(controls.rawMoveInput.x, 0, controls.rawMoveInput.y)) *
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
break;
case PlayerFacingDirection.MatchCamera:
// Craft a new rotation that flattens the camera's rotation to the ground
// Needed to keep the character from inheriting the camera's height-rotation
targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
break;
}
// Set final rotation
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
// Construct move direction
Vector3 finalMoveDir = Vector3.zero;
Vector3 gravityMoveDirection;
// Create movement direction for ground movement based on move direction, facing direction, and input
// Start by lerping facing direction towards move direction based on input power
rotationNoY = airMoveDirection.value;
rotationNoY.x = 0f;
rotationNoY.z = 0f;
// agent.transform.rotation = Quaternion.RotateTowards(agent.transform.rotation, Quaternion.Euler(rotationNoY), )
// Vector3 groundMoveDirModified = Vector3.Lerp();
// Add input movement
if (agent.isGrounded){
Quaternion cameraRotNoY = Quaternion.Euler(0f, Camera.main.transform.rotation.eulerAngles.y , 0f);
finalMoveDir += groundMoveDirection.value + Vector3.down * .03f;
gravityMoveDirection = new(0f, jumpPower.value + (Physics.gravity.y *.08f), 0f);
gravityMoveDirection = new(0f, jumpPower.value + (Physics.gravity.y *.3f), 0f);
} else {
finalMoveDir += airMoveDirection.value;
gravityMoveDirection = new(0f, jumpPower.value + Physics.gravity.y * gravityPower.value, 0f);
}
// Do final movement
if (agent.isGrounded) {
agent.Move((Camera.main.transform.rotation * finalMoveDir + gravityMoveDirection) * Time.deltaTime);
} else {
agent.Move((finalMoveDir + gravityMoveDirection) * Time.deltaTime);
}
// Reset gravity power when grounded
if (agent.isGrounded) {
gravityPower.value = 0f;
}
// Do final movement
if (agent.isGrounded) {
agent.Move((Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f)) * finalMoveDir + gravityMoveDirection) * Time.deltaTime);
} else {
agent.Move((finalMoveDir + gravityMoveDirection) * Time.deltaTime);
}
// ???? Moved this above but don't remember if this needs to be here still
if (agent.isGrounded) {
jumpPower.value = 0f;
}
@@ -111,7 +133,6 @@ namespace NodeCanvas.Tasks.Actions {
// Gravity is processed in LateUpdate (added to MonoManager's onLateUpdate in OnInit())
public void LateUpdate(){
// Decay jump power
jumpPower.value = Mathf.Lerp(jumpPower.value, 0f, jumpPowerDecay.value * Time.deltaTime);
}

View File

@@ -1,50 +1,182 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using Sirenix.OdinInspector;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.UIElements;
using Vector2 = UnityEngine.Vector2;
using Vector3 = UnityEngine.Vector3;
public class LockOnManager : MonoBehaviour{
private CinemachineTargetGroup.Target playerTarget;
// Lock On settings
[Space(5)]
public float lockOnRange = 40f;
public float lockOnMaxAngle = 70f;
// Lock On Tracking
[Space(10)] public GameObject lockonGameObject; // Needed because nulling the Target below doesn't actually empty it out
[ReadOnly] public CinemachineTargetGroup.Target lockonTarget;
public CinemachineTargetGroup targetGroup;
[Space(5)]
public List<GameObject> lockOnTargets = new List<GameObject>();
// UI
[ShowInInspector]
public UIDocument lockOnDocument;
public GameObject lockOnTarget;
private Label elementLabelName;
private VisualElement elementRoot;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
if (lockOnTarget.GetComponent<ILockOnTarget>() == null) {
Debug.LogError($"Game Object {lockOnTarget.name} does not implement the ILockOnTarget interface. Not processing lock-on actions!");
void Start(){
// Save the player target object to track later
playerTarget = targetGroup.Targets[0];
// Quick check for things in lock-on target that aren't lock-onable
if (lockonGameObject != null && lockonTarget.Object.GetComponent<ILockOnTarget>() == null) {
Debug.LogError($"Game Object {lockonTarget.Object.name} does not implement the ILockOnTarget interface!");
}
elementRoot = lockOnDocument.rootVisualElement.Query<VisualElement>("LockOnGroup");
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
// Add all nearby game objects to lock-on eligible list
GameObject[] allGameObjects = GameObject.FindObjectsByType<GameObject>(0, 0);
foreach (GameObject thisObject in allGameObjects)
{
if (Vector3.Distance(transform.position, thisObject.transform.position) < lockOnRange) {
if (thisObject.GetComponent<ILockOnTarget>() != null) {
lockOnTargets.Add(thisObject);
}
}
}
}
void Update(){
if (lockonGameObject && lockonTarget.Object.GetComponent<ILockOnTarget>() == null) {
Debug.LogError($"Game Object {lockonTarget.Object.name} does not implement the ILockOnTarget interface!");
}
// Find the current lock-on target and increase it's weight to the .15f max slowly
// They start at 0 weight when the lock-on adds them to the group
if (lockonGameObject) {
CinemachineTargetGroup.Target currentTarget = targetGroup.Targets.Find(target => target == lockonTarget);
currentTarget.Weight = Mathf.MoveTowards(currentTarget.Weight, .15f, .5f * Time.deltaTime);
}
// If a target is not the current lock on target, lower their targeting weight. When low enough to not cause a sharp jitter, remove them.
for (int i = 1; i < targetGroup.Targets.Count; i++) {
if (targetGroup.Targets[i] == lockonTarget || targetGroup.Targets[i] == playerTarget){
continue;
}
if (targetGroup.Targets[i].Weight < 0.001f) {
StartCoroutine(RemoveFromTargetAtFrameEnd(targetGroup.Targets[i]));
continue;
}
targetGroup.Targets[i].Weight = Mathf.MoveTowards(targetGroup.Targets[i].Weight, 0f, 1f * Time.deltaTime);
}
}
IEnumerator RemoveFromTargetAtFrameEnd(CinemachineTargetGroup.Target indexOf){
yield return new WaitForEndOfFrame();
targetGroup.Targets.Remove(indexOf);
}
public void ChangeLockOnTarget(){
Transform cameraTransform = Camera.main.transform;
// If there is no target, simply find the closest to the center of the camera
GameObject closestTarget = null;
float lowestDistanceToCenter = Mathf.Infinity;
foreach (GameObject target in lockOnTargets) {
// Skip the current target if one exists
if (lockonGameObject != null && lockonTarget.Object.gameObject == target) {
continue;
}
// Skip targets currently behind objects.
Physics.Raycast(cameraTransform.position,
cameraTransform.position.DirectionTo(target.transform.position), out RaycastHit hit);
if (hit.transform != target.transform) {
continue;
}
// Skip targets outside lock on angle
float angleFromCameraForward = Vector3.Angle(cameraTransform.forward, cameraTransform.position.DirectionTo(target.transform.position));
if (angleFromCameraForward > lockOnMaxAngle) {
continue;
}
// Find how close this target is from the center of the screen
Vector3 targetScreenPoint = Camera.main.WorldToScreenPoint(target.transform.position);
float distanceFromScreenCenter = targetScreenPoint.Flatten(null, null, 0f).magnitude - new Vector3(Screen.width, Screen.height, 0f).magnitude / 2f;
distanceFromScreenCenter = Mathf.Abs(distanceFromScreenCenter);
// Debug.Log($"{target.name}: {distanceFromScreenCenter} pixels, {angleFromCameraForward} degrees");
// Set the new target to closest to screen
if (distanceFromScreenCenter < lowestDistanceToCenter) {
lowestDistanceToCenter = distanceFromScreenCenter;
closestTarget = target;
}
}
// Catch exception from nothing being found
if (!closestTarget) {
Debug.LogWarning("Lock-on attempted, but no lock on target was found viable.");
return;
}
// Create a new Target for the Target Group
var newTarget = new CinemachineTargetGroup.Target{
Object = closestTarget.transform,
Radius = 1f,
Weight = 0f
};
// Set the new target variables
lockonTarget = newTarget;
lockonGameObject = closestTarget.gameObject;
targetGroup.Targets.Add(newTarget);
}
public void RemoveLockOnTarget(){
lockonTarget = null;
lockonGameObject = null;
}
// Update is called once per frame
void LateUpdate(){
if (lockOnTarget.GetComponent<ILockOnTarget>() != null) {
if (lockonGameObject) {
// This is just test logic to get an image above a lock on.
// TODO: Replace with something less silly
Vector2 screenPos = RuntimePanelUtils.CameraTransformWorldToPanel(
lockOnDocument.rootVisualElement.panel,
lockOnTarget.GetComponent<ILockOnTarget>().GetReticlePosition(),
Camera.main.GetComponent<Camera>()
lockOnDocument.rootVisualElement.panel,
lockonTarget.Object.GetComponent<ILockOnTarget>().GetReticlePosition(),
Camera.main
);
// Set name
elementLabelName.name = lockOnTarget.name;
elementLabelName.text = lockonTarget.Object.name;
// Set position (add the width/height of the element)
elementRoot.style.top = new StyleLength(screenPos.y - elementRoot.resolvedStyle.height * .7f );
elementRoot.style.top = new StyleLength(screenPos.y - 25f); // Was elementRoot.resolvedStyle.height * .7f
elementRoot.style.left = new StyleLength(screenPos.x - elementRoot.resolvedStyle.width / 2f);
// Set enabled
elementRoot.SetEnabled(true);
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
} else {
elementRoot.SetEnabled(false);
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
}
}

View File

@@ -1,7 +1,7 @@
using System;
using UnityEngine;
public interface ILockOnTarget{
public interface ILockOnTarget {
public float lockonTargetRadius { set; }
Transform transform {get;}

View File

@@ -39,4 +39,15 @@ public class PlayerControls : MonoBehaviour{
public void OnJump(){
graph.SendEvent<string>("InputEvent", "Jump", null);
}
public void OnLockOn(){
GetComponent<LockOnManager>().ChangeLockOnTarget();
graph.SendEvent<string>("InputEvent", "LockOn", null);
}
public void OnCancelLockOn(){
GetComponent<LockOnManager>().RemoveLockOnTarget();
graph.SendEvent<string>("InputEvent", "CancelLockOn", null);
}
}

View File

@@ -7,7 +7,8 @@
"GUID:66c2eb417c67ad849907d0769db96dbf",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:de4e6084e6d474788bb8c799d6b461ec",
"GUID:d8b63aba1907145bea998dd612889d6b"
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:4307f53044263cf4b835bd812fc161a4"
],
"includePlatforms": [],
"excludePlatforms": [],