Under the AgentSoldier/Actions GameObject

  1. Add an empty GameObject and call it GoTo
  2. Create a GoToAction C# class and attach it on the GoTo Game Object.
using SGoap;
using UnityEngine;

public class GoToAction : BasicAction
{
    public Transform Target;

    public float Range = 4;
    public float MoveSpeed = 2;

    public override EActionStatus Perform()
    {
				AgentData.Target = Target;

        var distanceToTarget = Vector3.Distance(Target.position, transform.position);
        if (distanceToTarget <= Range)
            return EActionStatus.Success;

        var directionToTarget = (Target.position - transform.position).normalized;
        AgentData.Position += directionToTarget * Time.deltaTime * MoveSpeed;

				// Returning Running will keep this action going until we return Success.
        return EActionStatus.Running;
    }
}

Set your MainCamera position to (0,0,-20)

https://i.imgur.com/DZ2ICM6.png

Create a Sphere named Target and set its position at (0,0,0)

https://i.imgur.com/tpIB2jG.png

Set your SoldierAgent position to (-10,0,0)

https://i.imgur.com/LH7Dnn7.png

Under the AgentSoldier/Actions/Goto GameObject

  1. Attach the GoToAction script
  2. (Optional) Set the name to Go To
  3. Assign the Target to Target (The sphere)
  4. Add a precondition InShootingRange ! = (This action can only start if the agent is not in shooting range) make sure you click the ! = Operator!
  5. Add an effect InShootingRange

https://i.imgur.com/oQlMGi8.png

We're almost there!