public static BTResult MoveTo(Animal agent, Vector3 target, bool wandering) { var routeProps = new RouteProperties { MaxTargetLocationHeightDelta = agent.Species.ClimbHeight }; var route = AIUtil.GetRouteFacingTarget(agent.FacingDir, agent.Position, target, agent.Species.GetTraversalData(wandering), agent.Species.HeadDistance * 2, routeProps: routeProps, allowBasic: false); if (!route.IsValid) { return(BTResult.Failure("Can't build route")); } // Prevent setting route with 0 time length var timeToFinishRoute = agent.SetRoute(route, wandering ? AnimalState.Wander : AnimalState.Flee); if (timeToFinishRoute < float.Epsilon) { return(BTResult.Failure("route not set")); } return(BTResult.RunningChanged("Moving to target")); }
static BTResult DoSleepNearLeader(Behavior <Animal> beh, Animal agent) { var leader = GetLeader(agent); if (leader == null) { return(BTResult.Failure("No leader")); } if (leader == agent) { return(BTResult.Failure("We are leader")); } //If the leader is sleeping... if (leader.State == AnimalState.Sleeping) { // and we're already close enough, sleep now. if (Vector3.WrappedDistance(agent.Position, leader.Position) < agent.Species.HeadDistance * 3) { return(agent.ChangeState(AnimalState.LyingDown, 60f, true)); } //Otherwise, move to them to sleep. // TODO: avoid overlapping with other herd members, make the leader pick a spot to sleep that can accommodate the herd var routeProps = new RouteProperties { MaxTargetLocationHeightDelta = agent.Species.ClimbHeight }; var route = AIUtil.GetRouteFacingTarget(agent.FacingDir, agent.Position, leader.Position, agent.Species.GetTraversalData(true), agent.Species.HeadDistance * 2, routeProps: routeProps); if (!route.IsValid) { return(BTResult.Failure("can't get route to leader")); } agent.SetRoute(route, AnimalState.Wander); return(BTResult.Success("walking to sleep near leader")); } return(BTResult.Failure("leader not sleeping")); }