private TaskStatus StartMove(NpcHtnContext c) { if (c.CurrentTarget == null) { return(TaskStatus.Failure); } // To get random position AROUND the target object Bounds bounds = c.CurrentTarget.GetComponent <Collider>().bounds; Vector3 randomizePosition = bounds.center + new Vector3(bounds.extents.x * Random.Range(-1f, 1f), 0, bounds.extents.z * Random.Range(-1f, 1f)); // MaxDistance = 1000 simply because we don't want to be really limited by scale of objects NavMeshHit hit; if (NavMesh.SamplePosition(randomizePosition, out hit, 1000f, NavMesh.AllAreas)) { if (c.NavAgent.SetDestination(hit.position)) { c.NavAgent.isStopped = false; return(TaskStatus.Continue); } return(TaskStatus.Failure); } return(TaskStatus.Failure); }
private TaskStatus CheckForSuccess(NpcHtnContext c) { if (!c.NavAgent.pathPending && c.NavAgent.remainingDistance <= c.NavAgent.radius) { c.NavAgent.isStopped = true; c.anim.SetBool("IsRunning", false); return(TaskStatus.Success); } return(TaskStatus.Continue); }
private bool CheckForWanderTargetReached(NpcHtnContext c) { if (!c.NavAgent.pathPending && c.NavAgent.remainingDistance <= c.NavAgent.radius) { c.NavAgent.isStopped = true; c.anim.SetBool("IsRunning", false); return(true); } return(false); }
private TaskStatus Move(NpcHtnContext c) { // if (c.policesInRange.Count > 0 && c.NavAgent.SetDestination(_targetPos) ) { if (c.NavAgent.SetDestination(_targetPos)) { c.NavAgent.isStopped = false; c.anim.SetBool("IsRunning", true); return(TaskStatus.Continue); } return(TaskStatus.Failure); }
private TaskStatus Move(NpcHtnContext c) { if (c.NavAgent.SetDestination(c.MoveToTarget)) { c.NavAgent.isStopped = false; c.anim.SetBool("IsRunning", true); return(TaskStatus.Continue); } return(TaskStatus.Failure); }
private TaskStatus StartWander(NpcHtnContext c) { // Random position around self Vector3 randPos = c.Position + new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) * _wanderRadius; if (c.NavAgent.SetDestination(randPos)) { c.NavAgent.isStopped = false; c.anim.SetBool("IsRunning", true); return(TaskStatus.Continue); } return(TaskStatus.Failure); }
private Vector3 GetPosFromType(NpcHtnContext ctx, NpcType fleeType) { Vector3 posToFleeTo; switch (fleeType) { case NpcType.Police: posToFleeTo = ctx.Position - (ctx.ClosestPolice.transform.position - ctx.Position).normalized * 20; break; default: throw new ArgumentOutOfRangeException(nameof(fleeType), fleeType, null); } return(posToFleeTo); }
public void Init(NpcHtnContext context) { Context = context; }