This commit is contained in:
CortexCore
2023-12-16 23:30:08 +08:00
parent 78216a3d47
commit 961ae8feb4
33 changed files with 369 additions and 148 deletions

View File

@@ -15,6 +15,7 @@ namespace NodeCanvas.Tasks.Actions
public BBParameter<GameObject> target;
public BBParameter<float> speed = 4;
public BBParameter<float> keepDistance = 0.1f;
public BBParameter<bool> waitUntilFinish = false;
private Vector3? lastRequest;
@@ -29,16 +30,21 @@ namespace NodeCanvas.Tasks.Actions
EndAction(true);
return;
}
}
protected override void OnUpdate() {
if ( target.value == null ) { EndAction(false); return; }
var pos = target.value.transform.position;
if ( lastRequest != pos ) {
if ( !agent.SetDestination(pos) ) {
if (lastRequest != pos)
{
if (!agent.SetDestination(pos))
{
EndAction(false);
return;
}
if (waitUntilFinish.value == false)
EndAction(true);
}
lastRequest = pos;
@@ -46,11 +52,13 @@ namespace NodeCanvas.Tasks.Actions
if ( !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value ) {
EndAction(true);
}
}
protected override void OnPause() { OnStop(); }
protected override void OnStop() {
if ( agent.gameObject.activeSelf ) {
if ( agent.gameObject.activeSelf && agent.isOnNavMesh && waitUntilFinish.value) {
agent.ResetPath();
}
lastRequest = null;

View File

@@ -58,7 +58,7 @@ namespace NodeCanvas.Tasks.Actions
protected override void OnPause() { OnStop(); }
protected override void OnStop() {
if ( agent.gameObject.activeSelf ) {
if ( agent.gameObject.activeSelf && agent.isOnNavMesh) {
agent.ResetPath();
}
}

View File

@@ -23,7 +23,7 @@ namespace NodeCanvas.Tasks.Conditions
public BBParameter<float> viewAngle = 70f;
public Vector3 offset;
public Transform blockingObject;
public string report;
private RaycastHit hit;
@@ -41,29 +41,46 @@ namespace NodeCanvas.Tasks.Conditions
if ( Vector3.Distance(agent.position, t.position) <= awarnessDistance.value ) {
if ( Physics.Linecast(agent.position + offset, t.position + offset, out hit, layerMask.value) ) {
blockingObject = hit.collider.transform;
if ( hit.collider != t.GetComponent<Collider>() ) {
return false;
report = hit.collider.name;
}
}
report = "Good Vigil Direct Hit";
return true;
}
if ( Vector3.Distance(agent.position, t.position) > maxDistance.value ) {
report = "Out of max distance";
return false;
}
if ( Vector3.Angle(t.position - agent.position, agent.forward) > viewAngle.value ) {
// if ( Vector3.Angle(t.position - agent.position, agent.forward) > viewAngle.value ) {
// report = "Out of view angle";
// return false;
// }
var direction = t.position - agent.position;
var dir = Quaternion.LookRotation(direction);
var angle = Quaternion.Angle(agent.rotation, dir);
if (Vector3.Dot(agent.forward, direction) > 0 && viewAngle.value > angle)
{
}
else
{
report = $"Out of view angle:{angle}";
return false;
}
if ( Physics.Linecast(agent.position + offset, t.position + offset, out hit, layerMask.value) ) {
blockingObject = hit.collider.transform;
if ( hit.collider != t.GetComponent<Collider>() ) {
report = hit.collider.name;
return false;
}
}
report = "Good Vigil";
return true;
}