fix: more movement and observer tweaks and fixes
This commit is contained in:
@@ -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;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user