Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: tchrisbaker on July 02, 2016, 04:07:19 AM
-
I created a debugging action for tracking a character's NavMeshAgent path. It will draw a Debug line from the character to each point in the path.
If the path is white, it is complete and therefore successful, yellow is partial and red is invalid.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Debug)]
public class PathUtils : FsmStateAction {
[RequiredField]
[Tooltip("The Game Object to work with. NOTE: The Game Object must have a NavMeshAgent component attached.")]
[CheckForComponent(typeof(NavMeshAgent))]
public FsmOwnerDefault gameObject;
private NavMeshAgent agent;
private Color color;
private void _getAgent()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
agent = go.GetComponent<NavMeshAgent>();
}
public override void OnEnter() {
_getAgent ();
}
public override void OnUpdate()
{
DrawPath (agent.path);
}
void DrawPath(NavMeshPath path) {
if (path.corners.Length < 2)
return;
switch (path.status) {
case NavMeshPathStatus.PathComplete:
color = Color.white;
break;
case NavMeshPathStatus.PathInvalid:
color = Color.red;
break;
case NavMeshPathStatus.PathPartial:
color = Color.yellow;
break;
}
Vector3 previousCorner = path.corners[0];
int i = 1;
while (i < path.corners.Length) {
Vector3 currentCorner = path.corners[i];
Debug.DrawLine(previousCorner, currentCorner, color);
previousCorner = currentCorner;
i++;
}
}
}
}
-
Sounds very useful- thanks :)
-
I know this is really old, but I only just stumbled across this action and it is incredibly useful.
This really ought to be part of the Pathfinding package.