added: graph tasks for agent transform and raycasthit processing
This commit is contained in:
121
Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs
Normal file
121
Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs
Normal 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 = Quaternion.Euler(relativeValue.value + 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 + 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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b77e2b9ac9aad644480508d5a86f4006
|
||||||
55
Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs
Normal file
55
Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs
Normal 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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 79f7cbb75d876f84b8edfae676ba324c
|
||||||
Reference in New Issue
Block a user