Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Empire on May 24, 2021, 04:17:12 PM
-
Any one know how I can get this to work? I can't seem to reference the transform from a fsm game object:
{
[RequiredField]
[Tooltip("The Game Object to work with. NOTE: The Game Object must have a NavMeshAgent component attached.")]
[CheckForComponent(typeof(UnityEngine.AI.NavMeshAgent))]
public FsmOwnerDefault gameObject;
public FsmGameObject thing2Avoid;
public float EnemyDistanceRun = 4.0f;
private UnityEngine.AI.NavMeshAgent _agent;
// Code that requires the navimesh agent.
private void _getAgent()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
_agent = go.GetComponent<UnityEngine.AI.NavMeshAgent>();
}
// Code that resets variables back to null.
public override void Reset()
{
gameObject = null;
}
// Code that runs on entering the state.
public override void OnEnter()
{
// Get the Navimesh agent
_getAgent();
// Invoke Method here
RunAway();
Finish();
}
void RunAway()
{
float distance = Vector3.Distance(Fsm.GameObject.transform.position, thing2Avoid.transform.position);
if (distance < EnemyDistanceRun)
{
Vector3 dirToPlayer = Fsm.GameObject.transform.position - thing2Avoid.transform.position;
Vector3 newPos = (Fsm.GameObject.transform.position + dirToPlayer) * 2;
_agent.SetDestination(newPos);
}
}
}
-
Nevermind, just had to convert the fsm game object to a Unity Game Object:
public FsmGameObject thing2Avoidfsm;
private GameObject thing2Avoid;
thing2Avoid = thing2Avoidfsm.Value;