IEnumerator FollowPath() { float moveDirection = CurrentGoal.GetDirFromPosition(transform.position); Rigidbody rigid = GetComponent <Rigidbody>(); CapsuleCollider collider = GetComponent <CapsuleCollider>(); rigid.velocity = Vector3.zero; //rigid.mass *= 10; rigid.drag = 10; while (moveDirection == m_s_STUCKDIRECTION) { yield return(null); moveDirection = CurrentGoal.GetDirFromPosition(transform.position); } //rigid.mass /= 10; rigid.drag = 0; while (moveDirection != m_s_ENDDIRECTION) { if (moveDirection == m_s_STUCKDIRECTION) { yield return(null); moveDirection = CurrentGoal.GetDirFromPosition(transform.position); continue; } if (moveDirection == int.MaxValue) { break; } transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, moveDirection, 0), m_Stats.m_TurnSpeed); //transform.rotation = Quaternion.Euler(0, moveDirection, 0); rigid.AddForce(transform.forward * m_Stats.m_Speed, ForceMode.VelocityChange); rigid.velocity = rigid.velocity.normalized * m_Stats.m_Speed * Time.deltaTime; //transform.Translate(Vector3.forward * Time.deltaTime * stats.speed, Space.Self); moveDirection = CurrentGoal.GetDirFromPosition(transform.position); yield return(null); if (collider.bounds.SqrDistance(CurrentGoal.Position) < collider.radius) { break; } } rigid.velocity = Vector3.zero; //rigid.mass *= 10; rigid.drag = 10; }
public async Task <GoapGoal?> GetAction() { if (playerReader.HealthPercent > 1 && blacklist.IsTargetBlacklisted()) { logger.LogWarning($"{GetType().Name}: Target is blacklisted - StopAttack & ClearTarget"); await input.TapStopAttack(""); await input.TapClearTarget(""); UpdateWorldState(); } var goal = new HashSet <KeyValuePair <GoapKey, GoapPreCondition> >(); //Plan Queue <GoapGoal> plan = planner.Plan(AvailableGoals, WorldState, goal); if (plan != null && plan.Count > 0) { if (CurrentGoal == plan.Peek() && !CurrentGoal.Repeatable) { logger.LogInformation($"Plan= {CurrentGoal.GetType().Name} is not Repeatable!"); CurrentGoal = null; } else { CurrentGoal = plan.Peek(); } } else { if (CurrentGoal != null && !CurrentGoal.Repeatable) { logger.LogInformation($"Plan= {CurrentGoal.GetType().Name} is not Repeatable!"); CurrentGoal = null; await stopMoving.Stop(); } } return(CurrentGoal); }
/// <summary> /// Checks the driver position to see if a knot or goal point has been reached. /// </summary> public void CheckPosition() { // If the driver has reached the current knot PathMutex.WaitOne(); if ((CurrentKnot != null) && (Math.Abs(X - CurrentKnot.X) < DistanceTolerance) && (Math.Abs(Y - CurrentKnot.Y) < DistanceTolerance)) { // Remove it from the path CurrentBestPath.RemoveKnot(1); } PathMutex.ReleaseMutex(); // If the driver has reached the current goal GoalMutex.WaitOne(); if ((Math.Abs(X - CurrentGoal.X) < DistanceTolerance) && (Math.Abs(Y - CurrentGoal.Y) < DistanceTolerance)) { // Move it to the end of the goals list Goals.Add(CurrentGoal.DeepClone()); Goals.Remove(CurrentGoal); } GoalMutex.ReleaseMutex(); }
private void OnKillCredit(object obj, EventArgs e) { if (Active) { GoapAgentState.IncKillCount(); if (CurrentGoal == null) { AvailableGoals.ToList().ForEach(x => x.OnActionEvent(this, new ActionEventArgs(GoapKey.producedcorpse, true))); } else { CurrentGoal.OnActionEvent(this, new ActionEventArgs(GoapKey.producedcorpse, true)); } logger.LogInformation($"{GetType().Name} --- Kill credit detected! Known kills: {GoapAgentState.LastCombatKillCount} | Combat mobs remaing: {addonReader.CombatCreatureCount}"); } else { logger.LogInformation($"{GetType().Name} --- Not active, but kill credit detected!"); } }