fix: more movement and observer tweaks and fixes
This commit is contained in:
@@ -14,7 +14,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
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,
|
_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":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,
|
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,
|
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,
|
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
|
_version: 3.31
|
||||||
_category:
|
_category:
|
||||||
_comments:
|
_comments:
|
||||||
_translation: {x: -337, y: -84}
|
_translation: {x: -106, y: -44}
|
||||||
_zoomFactor: 1
|
_zoomFactor: 1
|
||||||
_haltSerialization: 0
|
_haltSerialization: 0
|
||||||
_externalSerializationFile: {fileID: 0}
|
_externalSerializationFile: {fileID: 0}
|
||||||
|
|||||||
@@ -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<PlayerControls>{
|
|
||||||
[SliderField(0f,1f)]
|
|
||||||
public BBParameter<Vector3> desiredVector3;
|
|
||||||
public BBParameter<float> tolerance;
|
|
||||||
public BBParameter<bool> 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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
63
Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs
Normal file
63
Assets/Scripts/Core/Graph Tasks/CheckGenericObserver.cs
Normal file
@@ -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<Transform>{
|
||||||
|
[Space(5)]
|
||||||
|
public BBParameter<EnvironmentObserver.CastType> castType;
|
||||||
|
|
||||||
|
public BBParameter<float> length;
|
||||||
|
public BBParameter<Vector3> direction;
|
||||||
|
public BBParameter<Vector3> offset;
|
||||||
|
public BBParameter<LayerMask> ignoreLayers;
|
||||||
|
|
||||||
|
[ShowIf("castType", ((int)EnvironmentObserver.CastType.SphereCast|(int)EnvironmentObserver.CastType.SphereOverlap))]
|
||||||
|
public BBParameter<float> width;
|
||||||
|
|
||||||
|
public BBParameter<Vector3> size;
|
||||||
|
|
||||||
|
public BBParameter<Vector3> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fb4b5bf056649ca48b1b14dbe499de46
|
||||||
@@ -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<PlayerControls>{
|
||||||
|
enum CheckDotProductAgainst{
|
||||||
|
ForwardDirection,
|
||||||
|
CameraDirection,
|
||||||
|
InputVector3
|
||||||
|
}
|
||||||
|
|
||||||
|
[ExposeField, fsSerializeAs] CheckDotProductAgainst checkAgainst;
|
||||||
|
[ParadoxNotion.Design.ShowIf("checkAgainst", 2)] public BBParameter<Vector3> checkAgainstValue;
|
||||||
|
[SliderField(-1f, 1f)] public BBParameter<float> desiredValue;
|
||||||
|
public BBParameter<float> tolerance;
|
||||||
|
|
||||||
|
public BBParameter<bool> considerCameraRotation;
|
||||||
|
public BBParameter<bool> 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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,13 +90,16 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.Movement:
|
case PlayerFacingDirection.Movement:
|
||||||
// Check magnitude to avoid the "Look rotation viewing vector is zero" debug
|
// 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
|
// Set desired rotation to input direction, with respect to camera rotation
|
||||||
if (agent.isGrounded){
|
if (agent.isGrounded){
|
||||||
|
if (controls.rawMoveInput.magnitude == 0) { break; }
|
||||||
|
|
||||||
targetRotation = Quaternion.LookRotation(currentMoveDir) *
|
targetRotation = Quaternion.LookRotation(currentMoveDir) *
|
||||||
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
|
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
|
||||||
} else {
|
} else {
|
||||||
|
if (airMoveDirection.value.magnitude == 0) { break; }
|
||||||
|
|
||||||
targetRotation = Quaternion.LookRotation(airMoveDirection.value);
|
targetRotation = Quaternion.LookRotation(airMoveDirection.value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ public class EnvironmentObserver{
|
|||||||
IntersectingLength,
|
IntersectingLength,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ObserverGizmoDrawingCondition{
|
||||||
|
Always,
|
||||||
|
OnlyActive,
|
||||||
|
Never
|
||||||
|
}
|
||||||
|
|
||||||
public enum CastType{
|
public enum CastType{
|
||||||
Ray,
|
Ray,
|
||||||
BoxOverlap,
|
BoxOverlap,
|
||||||
@@ -42,7 +48,6 @@ public class EnvironmentObserver{
|
|||||||
[FoldoutGroup("Settings")] public Vector3 offset;
|
[FoldoutGroup("Settings")] public Vector3 offset;
|
||||||
[PropertySpace(0, 5), FoldoutGroup("Settings")] public LayerMask ignoreLayers = ~0;
|
[PropertySpace(0, 5), FoldoutGroup("Settings")] public LayerMask ignoreLayers = ~0;
|
||||||
|
|
||||||
|
|
||||||
[ShowIfGroup("Settings/CastsOnly", VisibleIf = "@castType == CastType.SphereCast || castType == CastType.SphereOverlap")]
|
[ShowIfGroup("Settings/CastsOnly", VisibleIf = "@castType == CastType.SphereCast || castType == CastType.SphereOverlap")]
|
||||||
[FoldoutGroup("Settings")] public float width;
|
[FoldoutGroup("Settings")] public float width;
|
||||||
|
|
||||||
@@ -71,27 +76,28 @@ public class EnvironmentObserver{
|
|||||||
[BoxGroup("Text/Hit")] public float hitTextSize;
|
[BoxGroup("Text/Hit")] public float hitTextSize;
|
||||||
[BoxGroup("Text/Hit")] public Vector3 hitLocationOffset;
|
[BoxGroup("Text/Hit")] public Vector3 hitLocationOffset;
|
||||||
[BoxGroup("Text/Hit")] public Vector3 hitRotationOffset;
|
[BoxGroup("Text/Hit")] public Vector3 hitRotationOffset;
|
||||||
|
[FoldoutGroup("Text"), SerializeField, ShowInInspector] ObserverGizmoDrawingCondition gizmoDrawingCondition;
|
||||||
|
|
||||||
[SerializeReference, PropertySpace(5, 5)]
|
[SerializeReference, PropertySpace(5, 5)]
|
||||||
public List<EnvironmentObserver> children;
|
public List<EnvironmentObserver> children;
|
||||||
|
|
||||||
// NOTE: I had a ref for a RaycastHit here that would correspond to hit but idk if it's needed.
|
// 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) {
|
if (active) {
|
||||||
// Remove player's layer from LayerMask.
|
// Remove player's layer from LayerMask.
|
||||||
ignoreLayers -= player.layer;
|
ignoreLayers -= source.layer;
|
||||||
|
|
||||||
// Set some of the variables used later during casting
|
// Set some of the variables used later during casting
|
||||||
Vector3 relativeStart = player.transform.position + offset;
|
Vector3 relativeStart = source.transform.position + offset;
|
||||||
Vector3 relativeStartWithRotation = player.transform.position + player.transform.rotation * offset ;
|
Vector3 relativeStartWithRotation = source.transform.position + source.transform.rotation * offset ;
|
||||||
|
|
||||||
switch (castType) {
|
switch (castType) {
|
||||||
case CastType.Ray:
|
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;
|
break;
|
||||||
case CastType.BoxOverlap:
|
case CastType.BoxOverlap:
|
||||||
overlapHits = Physics.OverlapBox(relativeStartWithRotation, size / 2f,
|
overlapHits = Physics.OverlapBox(relativeStartWithRotation, size / 2f,
|
||||||
player.transform.rotation * Quaternion.Euler(rotation), ignoreLayers);
|
source.transform.rotation * Quaternion.Euler(rotation), ignoreLayers);
|
||||||
|
|
||||||
if (overlapHits.Length > 0) {
|
if (overlapHits.Length > 0) {
|
||||||
return true;
|
return true;
|
||||||
@@ -103,8 +109,8 @@ public class EnvironmentObserver{
|
|||||||
case CastType.BoxCast:
|
case CastType.BoxCast:
|
||||||
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
|
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
|
||||||
if (Physics.BoxCast(relativeStartWithRotation, size / 2f,
|
if (Physics.BoxCast(relativeStartWithRotation, size / 2f,
|
||||||
player.transform.rotation * Quaternion.Euler(rotation) * direction,
|
source.transform.rotation * Quaternion.Euler(rotation) * direction,
|
||||||
out hit, player.transform.rotation * Quaternion.Euler(rotation), length,
|
out hit, source.transform.rotation * Quaternion.Euler(rotation), length,
|
||||||
ignoreLayers)
|
ignoreLayers)
|
||||||
) {
|
) {
|
||||||
};
|
};
|
||||||
@@ -112,7 +118,7 @@ public class EnvironmentObserver{
|
|||||||
case CastType.SphereCast:
|
case CastType.SphereCast:
|
||||||
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
|
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
|
||||||
if (Physics.SphereCast(relativeStartWithRotation, width / 2f,
|
if (Physics.SphereCast(relativeStartWithRotation, width / 2f,
|
||||||
player.transform.rotation * Quaternion.Euler(rotation) * direction,
|
source.transform.rotation * Quaternion.Euler(rotation) * direction,
|
||||||
out hit, length,
|
out hit, length,
|
||||||
ignoreLayers)
|
ignoreLayers)
|
||||||
) {
|
) {
|
||||||
@@ -127,29 +133,34 @@ public class EnvironmentObserver{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawObserverGizmo(GameObject player){
|
public void DrawObserverGizmo(GameObject source){
|
||||||
Vector3 relativeStart = player.transform.position + offset;
|
if (gizmoDrawingCondition == ObserverGizmoDrawingCondition.Never ||
|
||||||
Vector3 relativeStartWithRotation = player.transform.position + player.transform.rotation * (offset);
|
(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
|
// 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.
|
// 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 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
|
// 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);
|
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;
|
gizmoColor = active ? gizmoColor : Color.gray;
|
||||||
|
|
||||||
using (Draw.ingame.WithColor(gizmoColor)){
|
using (Draw.ingame.WithColor(gizmoColor)){
|
||||||
switch (castType) {
|
switch (castType) {
|
||||||
case CastType.Ray:
|
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;
|
break;
|
||||||
case CastType.BoxOverlap:
|
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;
|
break;
|
||||||
case CastType.SphereCast:
|
case CastType.SphereCast:
|
||||||
Draw.ingame.SolidCircle(relativeStartWithRotation, relativeStartWithRotation - Camera.main.transform.position, width * 1, gizmoColor.Alpha(.5f));
|
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;
|
Vector3 labelStartPos = Vector3.zero;
|
||||||
switch (labelTextLocation) {
|
switch (labelTextLocation) {
|
||||||
case LabelDrawingLocation.PlayerOffset:
|
case LabelDrawingLocation.PlayerOffset:
|
||||||
labelStartPos = player.transform.position;
|
labelStartPos = source.transform.position;
|
||||||
break;
|
break;
|
||||||
case LabelDrawingLocation.IntersectingLength:
|
case LabelDrawingLocation.IntersectingLength:
|
||||||
labelStartPos = offsetFromCenter;
|
labelStartPos = offsetFromCenter;
|
||||||
@@ -203,7 +214,7 @@ public class EnvironmentObserver{
|
|||||||
// Since the label is already drawn just use the previous startPos
|
// Since the label is already drawn just use the previous startPos
|
||||||
switch (labelTextLocation) {
|
switch (labelTextLocation) {
|
||||||
case LabelDrawingLocation.PlayerOffset:
|
case LabelDrawingLocation.PlayerOffset:
|
||||||
labelStartPos = player.transform.position;
|
labelStartPos = source.transform.position;
|
||||||
break;
|
break;
|
||||||
case LabelDrawingLocation.IntersectingLength:
|
case LabelDrawingLocation.IntersectingLength:
|
||||||
labelStartPos = offsetFromCenter;
|
labelStartPos = offsetFromCenter;
|
||||||
@@ -228,11 +239,7 @@ public class EnvironmentObserver{
|
|||||||
gizmoColor
|
gizmoColor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sirenix.Utilities.Editor.GUIHelper.RequestRepaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color GetObserverStatusColorStatic(bool active, RaycastHit hit){
|
static Color GetObserverStatusColorStatic(bool active, RaycastHit hit){
|
||||||
@@ -320,7 +327,6 @@ public class PlayerEnvironmentManager : MonoBehaviour{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Update(){
|
void Update(){
|
||||||
Debug.Log(EvaluateFromString("gamedev"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LateUpdate(){
|
void LateUpdate(){
|
||||||
|
|||||||
Reference in New Issue
Block a user