From 598fa9f6fc780d7e0018e09fefc25385d1296aa3 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 30 Jul 2025 13:22:36 -0400 Subject: [PATCH] fix: more movement and observer tweaks and fixes --- .../Player/Graphs/PlayerLocomotionFSM.asset | 4 +- .../Graph Tasks/CalculateInputDotProduct.cs | 47 ---------- .../Core/Graph Tasks/CheckGenericObserver.cs | 63 ++++++++++++++ .../Graph Tasks/CheckGenericObserver.cs.meta | 2 + .../Graph Tasks/GetMovementInputDotProduct.cs | 85 +++++++++++++++++++ ...eta => GetMovementInputDotProduct.cs.meta} | 0 .../Core/Graph Tasks/ProcessMovement.cs | 5 +- .../Player/PlayerEnvironmentManager.cs | 58 +++++++------ 8 files changed, 188 insertions(+), 76 deletions(-) delete mode 100644 Assets/Scripts/Core/Graph Tasks/CalculateInputDotProduct.cs create mode 100644 Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs create mode 100644 Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs.meta create mode 100644 Assets/Scripts/Core/Graph Tasks/GetMovementInputDotProduct.cs rename Assets/Scripts/Core/Graph Tasks/{CalculateInputDotProduct.cs.meta => GetMovementInputDotProduct.cs.meta} (100%) diff --git a/Assets/Player/Graphs/PlayerLocomotionFSM.asset b/Assets/Player/Graphs/PlayerLocomotionFSM.asset index 08d53b2..052abf5 100644 --- a/Assets/Player/Graphs/PlayerLocomotionFSM.asset +++ b/Assets/Player/Graphs/PlayerLocomotionFSM.asset @@ -14,7 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: _serializedGraph: '{"type":"NodeCanvas.StateMachines.FSM","nodes":[{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":12.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":10.0},"$type":"NodeCanvas.Tasks.Actions.SetFloat"},{"valueA":{"_name":"facingDirection","_targetVariableID":"c713d622-aafb-43e7-ae0e-ac0b86a85a37"},"valueB":{"_value":1},"$type":"NodeCanvas.Tasks.Actions.SetVariable`1[[Reset.Player.Movement.PlayerFacingDirection, Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}]},"_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":30.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":1.0},"$type":"NodeCanvas.Tasks.Actions.SetFloat"},{"valueA":{"_name":"facingDirection","_targetVariableID":"c713d622-aafb-43e7-ae0e-ac0b86a85a37"},"valueB":{"_value":2},"$type":"NodeCanvas.Tasks.Actions.SetVariable`1[[Reset.Player.Movement.PlayerFacingDirection, - Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}]},"_repeatStateActions":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_position":{"x":916.0607,"y":852.7302},"$type":"NodeCanvas.StateMachines.ActionState","$id":"1"},{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":20.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":2.0},"$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":"2"},{"_position":{"x":430.6569,"y":381.1322},"$type":"NodeCanvas.StateMachines.AnyState","$id":"3"},{"_position":{"x":465.0,"y":561.0},"$type":"NodeCanvas.StateMachines.EmptyState","$id":"4"}],"connections":[{"_condition":{"actionName":{"_value":"Sprint"},"actionValue":{"_value":""},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"timeout":{"_value":0.1},"$type":"NodeCanvas.Tasks.Conditions.Timeout"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"2"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"desiredVector3":{"_value":{"z":1.0}},"tolerance":{"_value":0.5},"negate":{},"$type":"NodeCanvas.Tasks.Conditions.GetMovementInputDotProduct"},"_sourceNode":{"$ref":"2"},"_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":"3"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"321e55c7-f93e-4667-a0dc-559eb61c6898"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"4"},"_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, + Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}]},"_repeatStateActions":true,"_color":{"r":1.0,"g":0.42,"b":0.32,"a":1.0},"_position":{"x":916.0607,"y":852.7302},"$type":"NodeCanvas.StateMachines.ActionState","$id":"1"},{"_actionList":{"executionMode":1,"actions":[{"moveSpeed":{"_value":20.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":2.0},"$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":"2"},{"_position":{"x":430.6569,"y":381.1322},"$type":"NodeCanvas.StateMachines.AnyState","$id":"3"},{"_position":{"x":465.0,"y":561.0},"$type":"NodeCanvas.StateMachines.EmptyState","$id":"4"}],"connections":[{"_condition":{"actionName":{"_value":"Sprint"},"actionValue":{"_value":""},"$type":"NodeCanvas.Tasks.Conditions.CheckInput"},"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"timeout":{"_value":0.1},"$type":"NodeCanvas.Tasks.Conditions.Timeout"},"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"2"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"checkAgainst":2,"checkAgainstValue":{"_value":{"z":1.0}},"desiredValue":{"_value":1.0},"tolerance":{"_value":0.32},"negate":{},"$type":"NodeCanvas.Tasks.Conditions.GetMovementInputDotProduct"},"_sourceNode":{"$ref":"2"},"_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":"3"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.StateMachines.FSMConnection"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"321e55c7-f93e-4667-a0dc-559eb61c6898"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_sourceNode":{"$ref":"4"},"_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]]"},"facingDirection":{"_name":"facingDirection","_id":"c713d622-aafb-43e7-ae0e-ac0b86a85a37","_isPublic":true,"$type":"NodeCanvas.Framework.Variable`1[[Reset.Player.Movement.PlayerFacingDirection, @@ -24,7 +24,7 @@ MonoBehaviour: _version: 3.31 _category: _comments: - _translation: {x: -337, y: -84} + _translation: {x: -106, y: -44} _zoomFactor: 1 _haltSerialization: 0 _externalSerializationFile: {fileID: 0} diff --git a/Assets/Scripts/Core/Graph Tasks/CalculateInputDotProduct.cs b/Assets/Scripts/Core/Graph Tasks/CalculateInputDotProduct.cs deleted file mode 100644 index 254b7e9..0000000 --- a/Assets/Scripts/Core/Graph Tasks/CalculateInputDotProduct.cs +++ /dev/null @@ -1,47 +0,0 @@ -using NodeCanvas.Framework; -using ParadoxNotion.Design; -using UnityEngine; - -namespace NodeCanvas.Tasks.Conditions { - - [Category("Core/Input")] - [Description("Returns a float from two Vector3s")] - public class GetMovementInputDotProduct : ConditionTask{ - [SliderField(0f,1f)] - public BBParameter desiredVector3; - public BBParameter tolerance; - public BBParameter negate; - - //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(){ - return null; - } - - //This is called once each time the task is enabled. - //Call EndAction() to mark the action as finished, either in success or failure. - //EndAction can be called from anywhere. - protected override bool OnCheck(){ - Vector3 rawInputVector3 = new(agent.rawMoveInput.x, 0f, agent.rawMoveInput.y); - float dotProduct = Vector3.Dot(desiredVector3.value, rawInputVector3); - - //Debug.Log(dotProduct); - - if (dotProduct < tolerance.value) { - return true; - } - - return false; - } - - //Called when the task is disabled. - protected override void OnEnable() { - - } - - //Called when the task is paused. - protected override void OnDisable() { - - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs b/Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs new file mode 100644 index 0000000..cc2749b --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs @@ -0,0 +1,63 @@ +using System.Drawing; +using NodeCanvas.Framework; +using ParadoxNotion.Design; +using UnityEngine; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Reset { + [Category("Reset")] + [Description("Creates an environment observer unattached from the player, such as for checking from the Camera or another arbitray location.")] + public class CheckGenericObserver : ConditionTask{ + [Space(5)] + public BBParameter castType; + + public BBParameter length; + public BBParameter direction; + public BBParameter offset; + public BBParameter ignoreLayers; + + [ShowIf("castType", ((int)EnvironmentObserver.CastType.SphereCast|(int)EnvironmentObserver.CastType.SphereOverlap))] + public BBParameter width; + + public BBParameter size; + + public BBParameter rotation; + + private EnvironmentObserver observer; + + //Return null if init was successfull. Return an error string otherwise + protected override string OnInit(){ + return null; + } + + //Called whenever the condition gets enabled. + protected override void OnEnable() { + observer = new EnvironmentObserver(){ + castType = EnvironmentObserver.CastType.SphereCast, + + length = length.value, + direction = direction.value, + offset = offset.value, + + width = width.value, + + size = size.value, + rotation = rotation.value + }; + } + + //Called whenever the condition gets disabled. + protected override void OnDisable() { + + } + + //Called once per frame while the condition is active. + //Return whether the condition is success or failure. + protected override bool OnCheck() { + return observer.Evaluate(agent.gameObject); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs.meta b/Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs.meta new file mode 100644 index 0000000..30a783c --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fb4b5bf056649ca48b1b14dbe499de46 \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/GetMovementInputDotProduct.cs b/Assets/Scripts/Core/Graph Tasks/GetMovementInputDotProduct.cs new file mode 100644 index 0000000..16c0ac1 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/GetMovementInputDotProduct.cs @@ -0,0 +1,85 @@ +using System; +using NodeCanvas.Framework; +using NUnit.Framework.Constraints; +using ParadoxNotion.Design; +using ParadoxNotion.Serialization.FullSerializer; +using Sirenix.OdinInspector; +using UnityEngine; + +namespace NodeCanvas.Tasks.Conditions { + + [Category("Reset/Input")] + [Description("Returns a float from two Vector3s")] + public class GetMovementInputDotProduct : ConditionTask{ + enum CheckDotProductAgainst{ + ForwardDirection, + CameraDirection, + InputVector3 + } + + [ExposeField, fsSerializeAs] CheckDotProductAgainst checkAgainst; + [ParadoxNotion.Design.ShowIf("checkAgainst", 2)] public BBParameter checkAgainstValue; + [SliderField(-1f, 1f)] public BBParameter desiredValue; + public BBParameter tolerance; + + public BBParameter considerCameraRotation; + public BBParameter negate; + + //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(){ + return null; + } + + //This is called once each time the task is enabled. + //Call EndAction() to mark the action as finished, either in success or failure. + //EndAction can be called from anywhere. + protected override bool OnCheck(){ + // Switch what the dot product is checked against + Vector3 valueToCheck; + + switch (checkAgainst) { + case CheckDotProductAgainst.ForwardDirection: + Debug.Log(agent.transform.forward); + valueToCheck = agent.transform.forward; + break; + case CheckDotProductAgainst.CameraDirection: + valueToCheck = Camera.main.transform.forward; + break; + case CheckDotProductAgainst.InputVector3: + valueToCheck = checkAgainstValue.value.normalized; + break; + default: + throw new ArgumentOutOfRangeException(); + } + + // Get the input as a Vector3 + Vector3 rawInputVector3 = new Vector3(agent.rawMoveInput.x, 0f, agent.rawMoveInput.y); + if (considerCameraRotation.value) { + rawInputVector3 = Camera.main.transform.rotation * rawInputVector3; + } + + // Calculate dor product + float dotProduct = Vector3.Dot(valueToCheck, rawInputVector3); + + Debug.Log(dotProduct); + + // Compare against the desired tolerance and output result + if (tolerance.value > Mathf.Abs(dotProduct - tolerance.value)) { + return true; + } + + return false; + } + + //Called when the task is disabled. + protected override void OnEnable() { + + } + + //Called when the task is paused. + protected override void OnDisable() { + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/CalculateInputDotProduct.cs.meta b/Assets/Scripts/Core/Graph Tasks/GetMovementInputDotProduct.cs.meta similarity index 100% rename from Assets/Scripts/Core/Graph Tasks/CalculateInputDotProduct.cs.meta rename to Assets/Scripts/Core/Graph Tasks/GetMovementInputDotProduct.cs.meta diff --git a/Assets/Scripts/Core/Graph Tasks/ProcessMovement.cs b/Assets/Scripts/Core/Graph Tasks/ProcessMovement.cs index de20385..bfab6d3 100644 --- a/Assets/Scripts/Core/Graph Tasks/ProcessMovement.cs +++ b/Assets/Scripts/Core/Graph Tasks/ProcessMovement.cs @@ -90,13 +90,16 @@ namespace NodeCanvas.Tasks.Actions { 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 if (agent.isGrounded){ + if (controls.rawMoveInput.magnitude == 0) { break; } + targetRotation = Quaternion.LookRotation(currentMoveDir) * Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f)); } else { + if (airMoveDirection.value.magnitude == 0) { break; } + targetRotation = Quaternion.LookRotation(airMoveDirection.value); } break; diff --git a/Assets/Scripts/Player/PlayerEnvironmentManager.cs b/Assets/Scripts/Player/PlayerEnvironmentManager.cs index 073c818..692309b 100644 --- a/Assets/Scripts/Player/PlayerEnvironmentManager.cs +++ b/Assets/Scripts/Player/PlayerEnvironmentManager.cs @@ -15,6 +15,12 @@ public class EnvironmentObserver{ IntersectingLength, } + enum ObserverGizmoDrawingCondition{ + Always, + OnlyActive, + Never + } + public enum CastType{ Ray, BoxOverlap, @@ -41,7 +47,6 @@ public class EnvironmentObserver{ [FoldoutGroup("Settings")] public Vector3 direction; [FoldoutGroup("Settings")] public Vector3 offset; [PropertySpace(0, 5), FoldoutGroup("Settings")] public LayerMask ignoreLayers = ~0; - [ShowIfGroup("Settings/CastsOnly", VisibleIf = "@castType == CastType.SphereCast || castType == CastType.SphereOverlap")] [FoldoutGroup("Settings")] public float width; @@ -71,27 +76,28 @@ public class EnvironmentObserver{ [BoxGroup("Text/Hit")] public float hitTextSize; [BoxGroup("Text/Hit")] public Vector3 hitLocationOffset; [BoxGroup("Text/Hit")] public Vector3 hitRotationOffset; - + [FoldoutGroup("Text"), SerializeField, ShowInInspector] ObserverGizmoDrawingCondition gizmoDrawingCondition; + [SerializeReference, PropertySpace(5, 5)] public List children; // NOTE: I had a ref for a RaycastHit here that would correspond to hit but idk if it's needed. - public bool Evaluate(GameObject player){ + public bool Evaluate(GameObject source){ if (active) { // Remove player's layer from LayerMask. - ignoreLayers -= player.layer; + ignoreLayers -= source.layer; // Set some of the variables used later during casting - Vector3 relativeStart = player.transform.position + offset; - Vector3 relativeStartWithRotation = player.transform.position + player.transform.rotation * offset ; + Vector3 relativeStart = source.transform.position + offset; + Vector3 relativeStartWithRotation = source.transform.position + source.transform.rotation * offset ; switch (castType) { case CastType.Ray: - Physics.Raycast(relativeStart, player.transform.rotation * direction, out hit, length, ignoreLayers); + Physics.Raycast(relativeStart, source.transform.rotation * direction, out hit, length, ignoreLayers); break; case CastType.BoxOverlap: overlapHits = Physics.OverlapBox(relativeStartWithRotation, size / 2f, - player.transform.rotation * Quaternion.Euler(rotation), ignoreLayers); + source.transform.rotation * Quaternion.Euler(rotation), ignoreLayers); if (overlapHits.Length > 0) { return true; @@ -103,8 +109,8 @@ public class EnvironmentObserver{ case CastType.BoxCast: // TODO: Make this not an if statement. Check that it works with NodeCanvas first if (Physics.BoxCast(relativeStartWithRotation, size / 2f, - player.transform.rotation * Quaternion.Euler(rotation) * direction, - out hit, player.transform.rotation * Quaternion.Euler(rotation), length, + source.transform.rotation * Quaternion.Euler(rotation) * direction, + out hit, source.transform.rotation * Quaternion.Euler(rotation), length, ignoreLayers) ) { }; @@ -112,7 +118,7 @@ public class EnvironmentObserver{ case CastType.SphereCast: // TODO: Make this not an if statement. Check that it works with NodeCanvas first if (Physics.SphereCast(relativeStartWithRotation, width / 2f, - player.transform.rotation * Quaternion.Euler(rotation) * direction, + source.transform.rotation * Quaternion.Euler(rotation) * direction, out hit, length, ignoreLayers) ) { @@ -127,29 +133,34 @@ public class EnvironmentObserver{ return false; } - public void DrawObserverGizmo(GameObject player){ - Vector3 relativeStart = player.transform.position + offset; - Vector3 relativeStartWithRotation = player.transform.position + player.transform.rotation * (offset); + public void DrawObserverGizmo(GameObject source){ + if (gizmoDrawingCondition == ObserverGizmoDrawingCondition.Never || + (gizmoDrawingCondition == ObserverGizmoDrawingCondition.OnlyActive ! & active)) { + return; + } + + Vector3 relativeStart = source.transform.position + offset; + Vector3 relativeStartWithRotation = source.transform.position + source.transform.rotation * (offset); // Setup the variables for boxcast, spherecast, etc // Create an offset start point for the center of the wirebox, since gizmos are drawn with their pivot in the center. Vector3 offsetWithRotationAndLength = (Quaternion.LookRotation(direction) * Quaternion.Euler(rotation)) * (Vector3.forward * (length / 2)); - Vector3 offsetFromCenter = relativeStartWithRotation + player.transform.rotation * offsetWithRotationAndLength; + Vector3 offsetFromCenter = relativeStartWithRotation + source.transform.rotation * offsetWithRotationAndLength; // Also create a rotation for use with the gizmos. Mainly just to shorten the lines - Quaternion gizmosRotation = player.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation); + Quaternion gizmosRotation = source.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation); Vector3 firstBoxOffset = gizmosRotation * (Vector3.forward * size.z); - Color gizmoColor = Evaluate(player) ? Color.green : Color.red; + Color gizmoColor = Evaluate(source) ? Color.green : Color.red; gizmoColor = active ? gizmoColor : Color.gray; using (Draw.ingame.WithColor(gizmoColor)){ switch (castType) { case CastType.Ray: - Draw.ingame.Line(relativeStart, relativeStart + (player.transform.rotation * direction.normalized) * length); + Draw.ingame.Line(relativeStart, relativeStart + (source.transform.rotation * direction.normalized) * length); break; case CastType.BoxOverlap: - Draw.ingame.WireBox(relativeStartWithRotation, player.transform.rotation * Quaternion.Euler(rotation), size); + Draw.ingame.WireBox(relativeStartWithRotation, source.transform.rotation * Quaternion.Euler(rotation), size); break; case CastType.SphereCast: Draw.ingame.SolidCircle(relativeStartWithRotation, relativeStartWithRotation - Camera.main.transform.position, width * 1, gizmoColor.Alpha(.5f)); @@ -173,7 +184,7 @@ public class EnvironmentObserver{ Vector3 labelStartPos = Vector3.zero; switch (labelTextLocation) { case LabelDrawingLocation.PlayerOffset: - labelStartPos = player.transform.position; + labelStartPos = source.transform.position; break; case LabelDrawingLocation.IntersectingLength: labelStartPos = offsetFromCenter; @@ -203,7 +214,7 @@ public class EnvironmentObserver{ // Since the label is already drawn just use the previous startPos switch (labelTextLocation) { case LabelDrawingLocation.PlayerOffset: - labelStartPos = player.transform.position; + labelStartPos = source.transform.position; break; case LabelDrawingLocation.IntersectingLength: labelStartPos = offsetFromCenter; @@ -228,11 +239,7 @@ public class EnvironmentObserver{ gizmoColor ); } - - Sirenix.Utilities.Editor.GUIHelper.RequestRepaint(); } - - } static Color GetObserverStatusColorStatic(bool active, RaycastHit hit){ @@ -320,7 +327,6 @@ public class PlayerEnvironmentManager : MonoBehaviour{ } void Update(){ - Debug.Log(EvaluateFromString("gamedev")); } void LateUpdate(){