Merge branch 'refs/heads/dev' into world/procgen-environment

This commit is contained in:
Chris
2025-08-01 20:36:40 -04:00
38 changed files with 1415 additions and 168 deletions

View File

@@ -10,19 +10,21 @@ using Reset.Player.Movement;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Movement")]
public class AddJump : ActionTask<CharacterController> {
public BBParameter<float> jumpStrength;
public BBParameter<Vector3> airMoveDirection;
public BBParameter<PlayerFacingDirection> playerFacingDirection;
public BBParameter<float> jumpPower;
[Range(0f, 1f)]
[Space(5)]
public BBParameter<float> jumpStrength;
[SliderField(0, 1)]
public BBParameter<float> standStillJumpStrength;
public BBParameter<float> jumpPower;
[Tooltip("Determines how much current movement vectors into jump direction")]
[SliderField(0, 1)]
public BBParameter<float> currentVelocityInheritence;
public BBParameter<Vector3> directionalForce;
[SliderField(0, 1)]
public BBParameter<float> directionalForceStrength;
protected override string info {
@@ -72,9 +74,12 @@ namespace NodeCanvas.Tasks.Actions {
// Check threshold of current XZ velocity- if it's too close to zero, use the jumpStrength for jumping velocity. If it's not, use the current velocity
float velocityThreshold = 4f;
float magnitudeZeroDifference = Mathf.Clamp(currentVelocityVector3.magnitude - velocityThreshold, 0f, Mathf.Infinity) / velocityThreshold; // Divided by maximum to return a 0-1 value. Clamping not required.
float outputVelocity = Mathf.Lerp(jumpStrength.value, currentVelocityVector3.magnitude, Math.Clamp(magnitudeZeroDifference, 0f, 1f));
float outputHoritontalVelocity = Mathf.Lerp(jumpStrength.value, currentVelocityVector3.magnitude, Math.Clamp(magnitudeZeroDifference, 0f, 1f));
outputHoritontalVelocity = Mathf.Min(outputHoritontalVelocity, Mathf.Lerp(standStillJumpStrength.value * jumpStrength.value, jumpStrength.value * .4f, magnitudeZeroDifference));
outputVelocity = Mathf.Min(outputVelocity, Mathf.Lerp(standStillJumpStrength.value * jumpStrength.value, jumpStrength.value * .4f, magnitudeZeroDifference));
// Do the same for directional jump strength
outputHoritontalVelocity = Mathf.Lerp(outputHoritontalVelocity, jumpStrength.value, directionalForceStrength.value);
// Remap the dot to set -1 (opposing direction) to -.5f, and 1 (same direciton) to 1.2f
// This is done to allow some sideways jumping direction change, but none backwards, and all forwards
@@ -94,7 +99,7 @@ namespace NodeCanvas.Tasks.Actions {
outputDirection = Camera.main.transform.rotation.Flatten(0, null, 0) * outputDirection;
// Set air move direction
airMoveDirection.value += outputDirection * outputVelocity;
airMoveDirection.value += outputDirection * outputHoritontalVelocity;
}
EndAction(true);
}

View File

@@ -3,16 +3,13 @@ using ParadoxNotion.Design;
using UnityEngine;
using Reset.Player.Movement;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Movement")]
public class CalculateAirMovement : ActionTask<Transform>{
public BBParameter<Vector3> airMoveDirection;
public BBParameter<Vector3> groundMoveDirection;
public BBParameter<Vector3> groundMoveDirection; // Unused on 7/29/25, delete if still unusued later
public BBParameter<PlayerFacingDirection> playerFacingDirection;
private float airControlPower = 1f;
//Use for initialization. This is called only once in the lifetime of the task.
@@ -25,7 +22,7 @@ namespace NodeCanvas.Tasks.Actions {
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute(){
airControlPower = 1f;
}
//Called once per frame while the action is active.
@@ -34,7 +31,7 @@ namespace NodeCanvas.Tasks.Actions {
airMoveDirection.value = Vector3.Lerp(airMoveDirection.value, Vector3.zero, .7f * Time.deltaTime);
// Decay Air Control power
airControlPower = Mathf.Lerp(airControlPower, 0f, 3f * Time.deltaTime);
airControlPower = Mathf.Lerp(airControlPower, 0f, 2f * Time.deltaTime);
// Add air control
Vector3 inputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
@@ -47,7 +44,7 @@ namespace NodeCanvas.Tasks.Actions {
//Called when the task is disabled.
protected override void OnStop() {
groundMoveDirection.value = agent.GetComponent<CharacterController>().velocity;
// groundMoveDirection.value = agent.GetComponent<CharacterController>().velocity;
EndAction(true);
}

View File

@@ -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() {
}
}
}

View File

@@ -0,0 +1,121 @@
using System;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Serialization.FullSerializer;
using Sirenix.OdinInspector;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset")]
[Description("Update the agent's position and rotation (scale too, sure whynot) either instantly or over time.")]
public class ChangeAgentTransform : ActionTask<CharacterController>{
public enum TransformProperty{
Position,
Rotation,
Scale
}
protected override string info {
get{
string basicText = string.Format($"Player {targetProperty.ToString()} to {(targetValue.isPresumedDynamic ? targetValue.name : targetValue.value)}");
basicText += relativeToSelf.value ? ", relative to Self" : "";
return basicText;
}
}
public TransformProperty targetProperty;
[ParadoxNotion.Design.ShowIf("targetProperty", 0), Space(5)]
public BBParameter<bool> forcePositionChange;
public BBParameter<Vector3> targetValue;
public BBParameter<bool> relativeToSelf;
[Tooltip("Set this to the current position if you're trying to rotate by 'this much'. Keep it zero for world space values.")]
public BBParameter<Vector3> relativeValue;
public BBParameter<bool> changeInstantly;
public BBParameter<float> smoothing;
private Vector3 currentVel;
//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 void OnExecute() {
switch (targetProperty) {
case TransformProperty.Position:
Vector3 relativeUseValue = relativeValue.value;
if (relativeToSelf.value) {
relativeUseValue = agent.transform.position;
}
if (changeInstantly.value) {
agent.Move(agent.transform.position.DirectionTo(relativeUseValue + targetValue.value));
}
break;
case TransformProperty.Rotation:
agent.transform.rotation = Quaternion.LookRotation(relativeValue.value) * Quaternion.Euler(targetValue.value);
break;
case TransformProperty.Scale:
break;
default:
throw new ArgumentOutOfRangeException();
}
if (changeInstantly.value) {
EndAction(true);
}
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
switch (targetProperty) {
case TransformProperty.Position:
Vector3 relativeUseValue = relativeValue.value;
if (relativeToSelf.value) {
relativeUseValue = agent.transform.position;
}
if (!changeInstantly.value) {
Vector3 targetPosition = relativeUseValue + targetValue.value;
// agent.transform.position = Vector3.SmoothDamp(agent.transform.position, targetPosition,
// ref currentVel, smoothing.value * Time.deltaTime);
agent.Move((agent.transform.position.DirectionTo(targetPosition)).normalized * .5f * Mathf.Lerp(0, 1, Vector3.Distance(agent.transform.position, targetPosition)) * smoothing.value * Time.deltaTime);
EndAction();
}
break;
case TransformProperty.Rotation:
agent.transform.rotation = Quaternion.Euler(relativeValue.value) * Quaternion.Euler(targetValue.value);
break;
case TransformProperty.Scale:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b77e2b9ac9aad644480508d5a86f4006

View File

@@ -147,7 +147,7 @@ public class Vector3CameraValueGroupDrawer : ObjectDrawer<Vector3CameraValueGrou
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.ToString(), labelOptions);
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
@@ -220,7 +220,7 @@ public class Vector2CameraValueGroupDrawer : ObjectDrawer<Vector2CameraValueGrou
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.ToString(), labelOptions);
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
@@ -326,8 +326,9 @@ namespace NodeCanvas.Tasks.Actions {
public class ChangeCameraSettings : ActionTask{
[ParadoxNotion.Design.Header("Main Settings")]
public FloatCameraValueGroup fieldOfView = new (newLabel: "FOV");
[ParadoxNotion.Design.Header("Orbit Follow Ring Settings")]
[ParadoxNotion.Design.Header("Orbit Follow Ring Settings"), Space (5)]
public Vector3CameraValueGroup orbitPositionDamping = new(newLabel: "Position Damping");
public OrbitalFollowValueGroup orbitFollowTop = new (newLabel: "Top");
public OrbitalFollowValueGroup orbitFollowCenter = new (newLabel: "Center");
public OrbitalFollowValueGroup orbitFollowBottom = new (newLabel: "Bottom");
@@ -336,7 +337,7 @@ namespace NodeCanvas.Tasks.Actions {
public Vector2CameraValueGroup screenPosition = new (newLabel: "Screen Position");
[ParadoxNotion.Design.Header("Camera Offset Settings")]
public Vector3CameraValueGroup cameraOffset = new (newLabel: "Screen Position");
public Vector3CameraValueGroup cameraOffset = new (newLabel: "Offset");
//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
@@ -461,6 +462,34 @@ namespace NodeCanvas.Tasks.Actions {
break;
}
// Position Damping
switch (orbitPositionDamping.changeX) {
case CameraSettingsToggle.NewValue:
CameraSettingsProcessor.values.orbitPositionDamping.targetValue.x = orbitPositionDamping.newValue.x;
break;
case CameraSettingsToggle.ResetValue:
CameraSettingsProcessor.values.orbitPositionDamping.targetValue.x = CameraSettingsProcessor.values.orbitPositionDamping.originalValue.x;
break;
}
switch (orbitPositionDamping.changeY) {
case CameraSettingsToggle.NewValue:
CameraSettingsProcessor.values.orbitPositionDamping.targetValue.y = orbitPositionDamping.newValue.y;
break;
case CameraSettingsToggle.ResetValue:
CameraSettingsProcessor.values.orbitPositionDamping.targetValue.y = CameraSettingsProcessor.values.orbitPositionDamping.originalValue.y;
break;
}
switch (orbitPositionDamping.changeZ) {
case CameraSettingsToggle.NewValue:
CameraSettingsProcessor.values.orbitPositionDamping.targetValue.z = orbitPositionDamping.newValue.z;
break;
case CameraSettingsToggle.ResetValue:
CameraSettingsProcessor.values.orbitPositionDamping.targetValue.z = CameraSettingsProcessor.values.orbitPositionDamping.originalValue.z;
break;
}
EndAction(true);
}

View File

@@ -0,0 +1,60 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Conditions {
[Category("Reset")]
public class CheckEnvironmentObserver : ConditionTask<PlayerEnvironmentManager>{
public BBParameter<string> observerLabel;
public BBParameter<RaycastHit> outputHitTo;
protected override string info{
get {
return $"Check Environment Observer, [\"{observerLabel.value}\"]";
}
}
//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(){
var observer = agent.FindObserverFromString(observerLabel.value);
if (observer == null) {
return $"An environment observer couldn't be found under the name {observerLabel.value}. Check your spelling and if it exists??";
}
return null;
}
//Called whenever the condition gets enabled.
protected override void OnEnable() {
agent.FindObserverFromString(observerLabel.value).active = true;
}
//Called whenever the condition gets disabled.
protected override void OnDisable() {
agent.FindObserverFromString(observerLabel.value).active = false;
}
//Called once per frame while the condition is active.
//Return whether the condition is success or failure.
protected override bool OnCheck(){
if (agent.EvaluateFromString(observerLabel.value) == true) {
if (outputHitTo.isDefined) {
EnvironmentObserver hitObserver = agent.FindObserverFromString(observerLabel.value, agent.observers);
if (hitObserver.hit.Equals(default(RaycastHit))) {
Debug.LogError("You just tried to pull a RaycastHit for later use from an environment observer, but no RaycastHit is available. Don't forget that CastType.Box and CastType.Sphere CANNOT spit one out!");
} else {
outputHitTo.value = hitObserver.hit;
return true;
}
}
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 95ad4bd047d9654478597c68a81b01a0

View File

@@ -0,0 +1,102 @@
using System.Drawing;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NodeCanvas.Editor;
using UnityEditor;
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;
public BBParameter<float> width;
public BBParameter<Vector3> size;
public BBParameter<Vector3> rotation;
public bool drawGizmos;
public bool drawGizmosOnlyWhenActive;
private EnvironmentObserver observer;
protected override void OnTaskInspectorGUI(){
BBParameterEditor.ParameterField("Cast Type", castType);
BBParameterEditor.ParameterField("Length", length);
BBParameterEditor.ParameterField("Direction", direction);
BBParameterEditor.ParameterField("Offset", offset);
BBParameterEditor.ParameterField("Ignore Layers", ignoreLayers);
if (castType.value == EnvironmentObserver.CastType.SphereCast || castType.value == EnvironmentObserver.CastType.SphereOverlap) {
BBParameterEditor.ParameterField("Width", width);
}
if (castType.value == EnvironmentObserver.CastType.BoxCast || castType.value == EnvironmentObserver.CastType.BoxOverlap) {
BBParameterEditor.ParameterField("Size", size);
}
if (castType.value != EnvironmentObserver.CastType.Ray) {
BBParameterEditor.ParameterField("Rotation", rotation);
}
drawGizmos = EditorGUILayout.Toggle("Draw Gizmos", drawGizmos);
if (drawGizmos) {
drawGizmosOnlyWhenActive = EditorGUILayout.Toggle("Draw Gizmos Only When Active", drawGizmosOnlyWhenActive);
}
}
//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 = castType.value,
active = true,
length = length.value,
direction = direction.value,
offset = offset.value,
ignoreLayers = ignoreLayers.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() {
bool check = observer.Evaluate(agent.gameObject);
if (drawGizmos) {
observer.DrawObserverGizmo(agent.gameObject, true);
}
return check;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fb4b5bf056649ca48b1b14dbe499de46

View File

@@ -1,49 +1,54 @@
using System;
using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
using UnityEngine.InputSystem;
namespace NodeCanvas.Tasks.Conditions {
[Category("Reset/Input")]
[Description("Check if input condition was matched this frame")]
[Description("Check if input condition was matched this frame by phase.")]
public class CheckInput : ConditionTask<Transform>{
public BBParameter<string> actionName;
public BBParameter<string> actionValue;
public BBParameter<InputActionPhase> actionPhase;
private SignalDefinition signalDefinition;
protected override string info {
get { return "Player Input"; }
get { return $"Input <b>{actionName.value}</b> was <b>{actionPhase.value}</b>"; }
}
private InputAction action;
//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(){
try {
signalDefinition = Resources.Load<SignalDefinition>("InputSignal");
} catch (Exception e) {
Debug.LogError($"Error finding the Input Signal defintion: {e.Message}");
throw;
}
return null;
}
//Called whenever the condition gets enabled.
protected override void OnEnable(){
action = agent.GetComponent<PlayerInput>().actions.FindAction(actionName.value);
protected override void OnEnable() {
signalDefinition.onInvoke -= OnSignalInvoke;
signalDefinition.onInvoke += OnSignalInvoke;
}
//Called whenever the condition gets disabled.
protected override void OnDisable() {
signalDefinition.onInvoke -= OnSignalInvoke;
}
//Called once per frame while the condition is active.
//Return whether the condition is success or failure.
protected override bool OnCheck() {
// if (action.type == InputActionType.Button){
if (action.WasPressedThisFrame()) { return true; }
// } else if (action.type == InputActionType.Value) {
//
// }
return false;
void OnSignalInvoke(Transform sender, Transform receiver, bool isGlobal, params object[] args){
// Take the input arguments as objects and convert them to InputAction & Phases
InputAction thisAction = (InputAction)args[0];
InputActionPhase thisActionPhase = (InputActionPhase)args[1];
if (actionName.value == thisAction.name && actionPhase.value == thisActionPhase) {
YieldReturn(true);
}
}
protected override bool OnCheck() { return false; }
}
}

View File

@@ -0,0 +1,55 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset")]
[Description("Breaks down an incoming RaycastHit into it's constituent parts for later use.")]
public class DecomposeRaycastHit : ActionTask{
public BBParameter<RaycastHit> raycastHit;
public BBParameter<Transform> transform;
public BBParameter<Collider> collider;
public BBParameter<GameObject> gameObject;
public BBParameter<float> distance;
public BBParameter<Vector3> normal;
public BBParameter<Vector3> point;
//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 void OnExecute(){
if (transform.isDefined){ transform.value = raycastHit.value.transform; }
if (collider.isDefined){ collider.value = raycastHit.value.collider; }
if (gameObject.isDefined){ gameObject.value = raycastHit.value.transform.gameObject; }
if (distance.isDefined){ distance.value = raycastHit.value.distance; }
if (normal.isDefined){ normal.value = raycastHit.value.normal; }
if (point.isDefined){ point.value = raycastHit.value.point; }
EndAction(true);
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 79f7cbb75d876f84b8edfae676ba324c

View File

@@ -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() {
}
}
}

View File

@@ -12,7 +12,8 @@ namespace Reset.Player.Movement{
public enum PlayerFacingDirection{
Target = 0,
Movement,
MatchCamera
MatchCamera,
Static
}
}
@@ -43,6 +44,7 @@ namespace NodeCanvas.Tasks.Actions {
private float currentRotSpeed;
private float lastLookMagnitude;
private Quaternion targetRotation;
private Vector3 currentMoveDir;
// References
private PlayerControls controls;
@@ -55,7 +57,7 @@ namespace NodeCanvas.Tasks.Actions {
// Append the late update method to actually happen on late update
MonoManager.current.onLateUpdate += LateUpdate;
// What
// Set ingitial rotation power
currentRotSpeed = rotationSpeed.value;
// Reference to controls
@@ -67,8 +69,8 @@ namespace NodeCanvas.Tasks.Actions {
//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 void OnExecute() {
protected override void OnExecute(){
currentMoveDir = groundMoveDirection.value;
}
//Called once per frame while the action is active.
@@ -88,26 +90,39 @@ 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
targetRotation = Quaternion.LookRotation(new Vector3(controls.rawMoveInput.x, 0, controls.rawMoveInput.y)) *
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
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;
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;
case PlayerFacingDirection.Static:
targetRotation = agent.transform.rotation;
break;
}
// Construct move direction
Vector3 finalMoveDir = Vector3.zero;
Vector3 gravityMoveDirection;
// Change how input is managed based on facing state
currentMoveDir = Vector3.Slerp(currentMoveDir, groundMoveDirection.value, currentRotSpeed * Time.deltaTime);
// Add input movement
if (agent.isGrounded){
finalMoveDir += groundMoveDirection.value + Vector3.down * .03f;
finalMoveDir += currentMoveDir + Vector3.down * .03f;
gravityMoveDirection = new(0f, jumpPower.value + (Physics.gravity.y *.3f), 0f);
} else {
finalMoveDir += airMoveDirection.value;
@@ -127,7 +142,7 @@ namespace NodeCanvas.Tasks.Actions {
}
// Set final rotation
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime).Flatten(0, null, 0);
// ???? Moved this above but don't remember if this needs to be here still
if (agent.isGrounded) {

View File

@@ -13,4 +13,7 @@ public static class MathExtensions{
return (to - origin).normalized;
}
public static Color Alpha(this Color input, float newAlpha){
return new Color(input.r, input.g, input.b, newAlpha);
}
}

View File

@@ -28,6 +28,8 @@ public struct CameraSettingSingleValue<T>{
public struct CameraSettingValues{
public CameraSettingSingleValue<float> mainFieldOfView;
public CameraSettingSingleValue<Vector3> orbitPositionDamping;
public CameraSettingSingleValue<float> orbitFollowTopHeight;
public CameraSettingSingleValue<float> orbitFollowTopRadius;
@@ -43,6 +45,8 @@ public struct CameraSettingValues{
public CameraSettingValues(float defaultSmoothing){
mainFieldOfView = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitPositionDamping = new CameraSettingSingleValue<Vector3>(defaultSmoothing);
orbitFollowTopHeight = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowTopRadius = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowCenterHeight = new CameraSettingSingleValue<float>(defaultSmoothing);
@@ -86,6 +90,7 @@ public class CameraSettingsProcessor : MonoBehaviour{
values = new CameraSettingValues{
cameraOffsetOffset = new CameraSettingSingleValue<Vector3>(defaultSmoothing: .2f, offset.Offset),
mainFieldOfView = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, main.Lens.FieldOfView),
orbitPositionDamping = new CameraSettingSingleValue<Vector3>(defaultSmoothing: .2f, orbit.TrackerSettings.PositionDamping),
orbitFollowTopHeight = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Top.Height),
orbitFollowTopRadius = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Top.Radius),
orbitFollowCenterHeight = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Center.Height),
@@ -101,6 +106,10 @@ public class CameraSettingsProcessor : MonoBehaviour{
values.mainFieldOfView.targetValue, ref values.mainFieldOfView.velocityRef,
values.mainFieldOfView.smoothing);
orbit.TrackerSettings.PositionDamping = Vector3.SmoothDamp(orbit.TrackerSettings.PositionDamping,
values.orbitPositionDamping.targetValue, ref values.orbitPositionDamping.velocityRefV3,
values.orbitPositionDamping.smoothing);
orbit.Orbits.Top.Height = Mathf.SmoothDamp(orbit.Orbits.Top.Height,
values.orbitFollowTopHeight.targetValue, ref values.orbitFollowTopHeight.velocityRef,
values.orbitFollowTopHeight.smoothing);
@@ -113,6 +122,8 @@ public class CameraSettingsProcessor : MonoBehaviour{
values.orbitFollowCenterHeight.targetValue, ref values.orbitFollowCenterHeight.velocityRef,
values.orbitFollowCenterHeight.smoothing);
orbit.Orbits.Center.Radius = Mathf.SmoothDamp(orbit.Orbits.Center.Radius,
values.orbitFollowCenterRadius.targetValue, ref values.orbitFollowCenterRadius.velocityRef,
values.orbitFollowCenterRadius.smoothing);

View File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -6,11 +7,15 @@ using UnityEngine.UIElements;
using NodeCanvas;
using NodeCanvas.Framework;
using ParadoxNotion;
using Sirenix.OdinInspector;
public class PlayerControls : MonoBehaviour{
// References
private Player thisPlayer;
private PlayerInput input;
public SignalDefinition inputSignal;
// TODO: Turn these into accessors
public Vector2 rawMoveInput;
public Vector2 rawLookInput;
@@ -20,6 +25,31 @@ public class PlayerControls : MonoBehaviour{
void Awake(){
thisPlayer = GetComponent<Player>();
graph = GetComponent<GraphOwner>();
input = GetComponent<PlayerInput>();
// Add the delegates for each method
foreach (InputAction action in input.actions) {
action.started += SendToGraph;
action.canceled += SendToGraph;
action.performed += SendToGraph;
}
}
// Remove the delegates for each method
void OnDisable(){
foreach (InputAction action in input.actions) {
action.started -= SendToGraph;
action.canceled -= SendToGraph;
action.performed -= SendToGraph;
}
}
// This will call the OnSignalInvoke for this type of Signal Defintion. CheckInput is the recieving end.
public void SendToGraph(InputAction.CallbackContext ctx){
inputSignal.Invoke(transform, transform, false, new object[]{
ctx.action,
ctx.phase
});
}
public void OnMove(InputValue value){

View File

@@ -0,0 +1,356 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Drawing;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using Unity.Mathematics;
using UnityEngine.Serialization;
[Serializable]
public class EnvironmentObserver{
enum LabelDrawingLocation{
PlayerOffset,
HitLocation,
IntersectingLength,
}
enum ObserverGizmoDrawingCondition{
Always,
OnlyActive,
Never
}
public enum CastType{
Ray,
BoxOverlap,
SphereOverlap,
BoxCast,
SphereCast
}
[PropertySpace(0, 5), LabelWidth(60)]
public string label;
[PropertySpace(0, 10), LabelWidth(60)]
public CastType castType;
[Button(ButtonSizes.Large), GUIColor("@GetObserverStatusColorStatic(active, hit)"), PropertyOrder(-1), PropertySpace(5, 5)]
public void Active(){
active = !active;
}
[HideInInspector]
public bool active;
// Parameters for Cast cast types
[FoldoutGroup("Settings")] public float length;
[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;
// Parameters for Overlap cast types
[ShowIfGroup("Settings/3DOnly", VisibleIf = "@castType == CastType.BoxCast && castType != CastType.BoxOverlap")] [FoldoutGroup("Settings")]
public Vector3 size;
[ShowIfGroup("Settings/3DOnly")]
public Vector3 rotation;
[HideInInspector]
public RaycastHit hit;
[HideInInspector]
public Collider[] overlapHits;
[FoldoutGroup("Text")]
[BoxGroup("Text/Label")] public bool drawLabel;
[ShowInInspector, SerializeField] [BoxGroup("Text/Label")] LabelDrawingLocation labelTextLocation;
[BoxGroup("Text/Label")] public float labelSize;
[BoxGroup("Text/Label")] public Vector3 labelLocationOffset;
[BoxGroup("Text/Label")] public Vector3 labelRotationOffset;
[BoxGroup("Text/Hit")] public bool drawHitName;
[ShowInInspector, SerializeField] [BoxGroup("Text/Hit")] LabelDrawingLocation hitTextLocation;
[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<EnvironmentObserver> 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 source){
if (active) {
// Remove player's layer from LayerMask.
ignoreLayers -= source.layer;
// Set some of the variables used later during casting
Vector3 relativeStart = source.transform.position + offset;
Vector3 relativeStartWithRotation = source.transform.position + source.transform.rotation * offset ;
switch (castType) {
case CastType.Ray:
Physics.Raycast(relativeStart, source.transform.rotation * direction, out hit, length, ignoreLayers);
break;
case CastType.BoxOverlap:
overlapHits = Physics.OverlapBox(relativeStartWithRotation, size / 2f,
source.transform.rotation * Quaternion.Euler(rotation), ignoreLayers);
if (overlapHits.Length > 0) {
return true;
};
break;
case CastType.SphereOverlap:
break;
case CastType.BoxCast:
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
if (Physics.BoxCast(relativeStartWithRotation, size / 2f,
source.transform.rotation * Quaternion.Euler(rotation) * direction,
out hit, source.transform.rotation * Quaternion.Euler(rotation), length,
ignoreLayers)
) {
};
break;
case CastType.SphereCast:
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
if (Physics.SphereCast(relativeStartWithRotation, width / 2f,
source.transform.rotation * Quaternion.Euler(rotation) * direction,
out hit, length,
ignoreLayers)
) {
};
break;
}
if (hit.transform != null) {
return true;
}
}
return false;
}
public void DrawObserverGizmo(GameObject source, bool drawAnyways = false){
if (!drawAnyways){
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 + source.transform.rotation * offsetWithRotationAndLength;
// Also create a rotation for use with the gizmos. Mainly just to shorten the lines
Quaternion gizmosRotation = source.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation);
Vector3 firstBoxOffset = gizmosRotation * (Vector3.forward * size.z);
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 + (source.transform.rotation * direction.normalized) * length);
break;
case CastType.BoxOverlap:
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));
Draw.ingame.WireCapsule(relativeStartWithRotation, relativeStartWithRotation + gizmosRotation * (Vector3.forward * (length - width / 2)), width);
break;
case CastType.BoxCast:
// Draw the gizmos for the boxcast
Draw.ingame.WireBox(offsetFromCenter, gizmosRotation, new float3(size.x, size.y, length));
Draw.ingame.SolidBox(relativeStartWithRotation, gizmosRotation, size, gizmoColor.Alpha(.1f));
Draw.ingame.WireBox(relativeStartWithRotation, gizmosRotation, size);
break;
default:
throw new ArgumentOutOfRangeException();
}
Draw.ingame.SolidCircle(relativeStartWithRotation, relativeStartWithRotation - Camera.main.transform.position, .4f);
Draw.ingame.SolidCircle(hit.point, hit.point - Camera.main.transform.position, .4f);
// Set up variables for label (not hit name)
Vector3 labelStartPos = Vector3.zero;
switch (labelTextLocation) {
case LabelDrawingLocation.PlayerOffset:
labelStartPos = source.transform.position;
break;
case LabelDrawingLocation.IntersectingLength:
labelStartPos = offsetFromCenter;
break;
case LabelDrawingLocation.HitLocation:{
if (hit.transform != null) {
labelStartPos = hit.point;
}
break;
}
}
// Draw label
if (drawLabel) {
Draw.ingame.Label3D(
labelStartPos + labelLocationOffset,
gizmosRotation * Quaternion.Euler(labelRotationOffset),
label,
labelSize,
LabelAlignment.MiddleLeft,
gizmoColor
);
}
// Set up variables for hit name
// Since the label is already drawn just use the previous startPos
switch (labelTextLocation) {
case LabelDrawingLocation.PlayerOffset:
labelStartPos = source.transform.position;
break;
case LabelDrawingLocation.IntersectingLength:
labelStartPos = offsetFromCenter;
break;
case LabelDrawingLocation.HitLocation:{
if (hit.transform != null) {
labelStartPos = hit.point;
}
break;
}
}
// Draw hitname
if (drawLabel) {
Draw.ingame.Label3D(
labelStartPos + labelLocationOffset,
gizmosRotation * Quaternion.Euler(labelRotationOffset),
label,
hitTextSize,
LabelAlignment.MiddleLeft,
gizmoColor
);
}
}
}
static Color GetObserverStatusColorStatic(bool active, RaycastHit hit){
if (active) {
if (hit.Equals(default(RaycastHit))) {
return Color.green;
}
return Color.red;
}
return Color.gray;
}
}
public class PlayerEnvironmentManager : MonoBehaviour{
[OdinSerialize]
public List<EnvironmentObserver> observers;
void Start(){
CheckDuplicateLabels(observers);
}
// TODO: Not working.
void CheckDuplicateLabels(List<EnvironmentObserver> sourceList){
foreach (EnvironmentObserver sourceObserver in observers) {
foreach (EnvironmentObserver observer in sourceList) {
if (sourceObserver == observer) {
continue;
}
if (sourceObserver.label == observer.label) {
Debug.LogError($"Duplicate label found in observer: {observer.label} is in use multiple times");
}
if (observer.children != null && observer.children.Count > 0) {
CheckDuplicateLabels(observer.children);
}
}
}
}
public bool EvaluateFromString(string searchLabel, List<EnvironmentObserver> observerList = null){
List<EnvironmentObserver> listToUse = observers;
if (observerList != null) {
listToUse = observerList;
}
foreach (EnvironmentObserver observer in listToUse) {
if (observer.label == searchLabel) {
return observer.Evaluate(gameObject);
}
if (observer.children != null && observer.children.Count > 0) {
foreach (EnvironmentObserver childObserver in observer.children) {
EvaluateFromString(searchLabel, childObserver.children);
}
}
}
return false;
}
public EnvironmentObserver FindObserverFromString(string searchLabel, List<EnvironmentObserver> observerList = null){
List<EnvironmentObserver> listToUse = observers;
if (observerList != null) {
listToUse = observerList;
}
foreach (EnvironmentObserver observer in listToUse) {
if (observer.label == searchLabel) {
return observer;
}
if (observer.children != null && observer.children.Count > 0) {
foreach (EnvironmentObserver childObserver in observer.children) {
FindObserverFromString(searchLabel, childObserver.children);
}
}
}
return null;
}
void Update(){
}
void LateUpdate(){
// Draw Gizmos
foreach (EnvironmentObserver observer in observers) {
observer.DrawObserverGizmo(gameObject);
if (observer.children != null && observer.children.Count > 0) {
foreach (EnvironmentObserver childObserver in observer.children) {
childObserver.DrawObserverGizmo(gameObject);
}
}
}
// Clear hit
foreach (EnvironmentObserver observer in observers) {
observer.hit = default;
if (observer.children != null && observer.children.Count > 0) {
foreach (EnvironmentObserver childObserver in observer.children) {
childObserver.hit = default;
}
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7a8c0593fef54844383c2f154cf8806c

View File

@@ -15,42 +15,42 @@ public class PlayerMovement : MonoBehaviour
thisPlayer = GetComponent<Player>();
}
void Update(){
// Create Ray Colors
Color forwardRayStatus = Color.red;
Color leftRayStatus = Color.red;
Color rightRayStatus = Color.red;
if (forwardRay.collider&& forwardRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ forwardRayStatus = Color.green;}
if (leftRay.collider&& leftRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ leftRayStatus = Color.green;}
if (rightRay.collider&& rightRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ rightRayStatus = Color.green;}
using (Draw.WithColor(forwardRayStatus)) {
Draw.Line(transform.position + transform.up, transform.position + transform.forward * 2.5f + transform.up);
}
// void Update(){
// // Create Ray Colors
// Color forwardRayStatus = Color.red;
// Color leftRayStatus = Color.red;
// Color rightRayStatus = Color.red;
//
// if (forwardRay.collider&& forwardRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ forwardRayStatus = Color.green;}
// if (leftRay.collider&& leftRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ leftRayStatus = Color.green;}
// if (rightRay.collider&& rightRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ rightRayStatus = Color.green;}
//
// using (Draw.WithColor(forwardRayStatus)) {
// Draw.Line(transform.position + transform.up, transform.position + transform.forward * 2.5f + transform.up);
// }
//
// using (Draw.WithColor(leftRayStatus)) {
// Draw.Line(transform.position + transform.up, transform.position + -transform.right * 2f + transform.up);
// }
//
// using (Draw.WithColor(rightRayStatus)) {
// Draw.Line(transform.position + transform.up, transform.position + transform.right * 2f + transform.up);
// }
// }
using (Draw.WithColor(leftRayStatus)) {
Draw.Line(transform.position + transform.up, transform.position + -transform.right * 2f + transform.up);
}
using (Draw.WithColor(rightRayStatus)) {
Draw.Line(transform.position + transform.up, transform.position + transform.right * 2f + transform.up);
}
}
void FixedUpdate(){
LayerMask environmentLayer = LayerMask.NameToLayer("Environment");
if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out forwardRay, 2.5f, ~environmentLayer)){
thisPlayer.controls.graph.SendEvent("ForwardRay", true, null);
}
if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.left, out leftRay, maxDistance: 2f, ~environmentLayer )) {
thisPlayer.controls.graph.SendEvent("LeftRay", true, null);
}
if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.right, out rightRay, maxDistance: 2f, ~environmentLayer )) {
thisPlayer.controls.graph.SendEvent("RightRay", true, null);
}
}
// void FixedUpdate(){
// LayerMask environmentLayer = LayerMask.NameToLayer("Environment");
//
// if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out forwardRay, 2.5f, ~environmentLayer)){
// thisPlayer.controls.graph.SendEvent("ForwardRay", true, null);
// }
//
// if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.left, out leftRay, maxDistance: 2f, ~environmentLayer )) {
// thisPlayer.controls.graph.SendEvent("LeftRay", true, null);
// }
//
// if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.right, out rightRay, maxDistance: 2f, ~environmentLayer )) {
// thisPlayer.controls.graph.SendEvent("RightRay", true, null);
// }
// }
}

View File

@@ -9,8 +9,7 @@
"GUID:de4e6084e6d474788bb8c799d6b461ec",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:4307f53044263cf4b835bd812fc161a4",
"GUID:4099e5319e98558428028d54bc62664e",
"GUID:1826c0224c0d048b88112c79bbb0cd85"
"GUID:e0cd26848372d4e5c891c569017e11f1"
],
"includePlatforms": [],
"excludePlatforms": [],