public bool Execute(AIActionList.Token token) { if (GetColliders.Get(out Collider2D col)) { FollowData.SetPosition(col.transform.position); if (Mathf.Abs(token.Source.Rigidbody.position.x - FollowData.Position.x) > FollowOffset) { return(Follow(token)); } } else if (FollowData.IsOn() && Mathf.Abs(token.Source.Rigidbody.position.x - FollowData.Position.x) > FollowOffset) { return(Follow(token)); } return(false); }
public bool Condition(IAIAction.IConditional.Token token) { if (token.Source.Character.GroundCheck.Evaluate()) { if (FollowGetColliders.Get(out Collider2D col)) { FollowData.SetPosition(col.transform.position); } else if (!FollowData.IsOn() || Vector2.Distance(FollowData.Position, token.Source.Rigidbody.position) < FollowOffset.x) { return(false); } Vector2 dir = FollowData.Position - token.Source.Rigidbody.position; if (Mathf.Abs(dir.y) < FollowOffset.y) { return(false); } bool belowY = dir.y < 0f; speed = belowY ? -token.Source.Speed.GetAscendingValue() : token.Source.Speed.GetAscendingValue(); if (dir.x > 0f) { // RIGHT token.Source.SpriteRenderer.flipX = false; if (SetRightSide(token, belowY)) { return(true); } } else { // LEFT token.Source.SpriteRenderer.flipX = true; if (SetLeftSide(token, belowY)) { return(true); } } if (currentDir != Direction.DOWN) { return(true); } } return(false); }