public void ChangeGroup(GroupCondition condition, int broId, PathFindingData pathFindingData) { this.condition = condition; this.broId = broId; this.pathFindingData = pathFindingData; conditionAdded = true; }
private void Awake() { if (null != sInstance && this != sInstance) { Destroy(this.gameObject); } sInstance = this; DontDestroyOnLoad(this.gameObject); }
private void FallWallJumpConnection(PathFindingData pfData, PathFindingNode pfNode, ConnectedNode cNode, FollowingPlayer followingPlayerScript, Vector3 pathfindingGameObjectSize) { if (cNode.preFallWallJumpDirectionSpeed > followingPlayerScript.maxSpeed) { cNode.preFallWallJumpDirectionSpeed = followingPlayerScript.maxSpeed; } else if (cNode.preFallWallJumpDirectionSpeed < -followingPlayerScript.maxSpeed) { cNode.preFallWallJumpDirectionSpeed = -followingPlayerScript.maxSpeed; } Vector2 fallWallJumpPlatformPos = cNode.fallWallJumpWall.transform.position; Vector2 fallWallJumpPlatformSizeDiv2 = cNode.fallWallJumpWall.transform.lossyScale / 2f; cNode.fallWallJumpStartX = pfNode.platformGameObject.transform.position.x + (pfNode.platformGameObject.transform.lossyScale.x / 2 + pfData.pathfindingGameObject.transform.lossyScale.x / 2) * (cNode.preFallWallJumpDirectionSpeed > 0 ? 1 : -1); cNode.firstFallWallJumpHit.x = fallWallJumpPlatformPos.x + (fallWallJumpPlatformSizeDiv2.x + pathfindingGameObjectSize.x / 2f) * (cNode.preFallWallJumpDirectionSpeed > 0f ? -1f : 1f); cNode.onPlatformValue = Math.Abs((cNode.firstFallWallJumpHit.x - cNode.fallWallJumpStartX) / cNode.preFallWallJumpDirectionSpeed); cNode.firstFallWallJumpHit.y = pfNode.objectOnFromPlatformY + followingPlayerScript.CalculateFallY(cNode.onPlatformValue); if (cNode.firstFallWallJumpHit.y < fallWallJumpPlatformPos.y - fallWallJumpPlatformSizeDiv2.y || cNode.firstFallWallJumpHit.y > fallWallJumpPlatformPos.y + fallWallJumpPlatformSizeDiv2.y || cNode.preFallWallJumpDirectionSpeed == 0f) { cNode.onPlatformValue = 1f; } FallVisualization(cNode.onPlatformValue, cNode.fallWallJumpStartX, cNode.preFallWallJumpDirectionSpeed, pfNode, cNode, followingPlayerScript, pathfindingGameObjectSize); if (cNode.fallWallJumpY > cNode.firstFallWallJumpHit.y) { cNode.fallWallJumpY = cNode.firstFallWallJumpHit.y; } else if (cNode.fallWallJumpY < fallWallJumpPlatformPos.y - fallWallJumpPlatformSizeDiv2.y) { cNode.fallWallJumpY = fallWallJumpPlatformPos.y - fallWallJumpPlatformSizeDiv2.y; } StraightFallVisualization(cNode.firstFallWallJumpHit.y, cNode.fallWallJumpY, cNode.firstFallWallJumpHit.x, pathfindingGameObjectSize); if (cNode.postFallWallJumpDirectionSpeed > followingPlayerScript.maxSpeed) { cNode.postFallWallJumpDirectionSpeed = followingPlayerScript.maxSpeed; } else if (cNode.postFallWallJumpDirectionSpeed < -followingPlayerScript.maxSpeed) { cNode.postFallWallJumpDirectionSpeed = -followingPlayerScript.maxSpeed; } cNode.onPlatformValue2 = 1; if (cNode.objectOnToPlatformY <= cNode.fallWallJumpY + followingPlayerScript.jumpHeight) { cNode.onPlatformValue2 = followingPlayerScript.CalculateXFromYInJump(cNode.objectOnToPlatformY - cNode.fallWallJumpY); } JumpVisualization(cNode.onPlatformValue2, cNode.firstFallWallJumpHit.x, cNode.fallWallJumpY, cNode.postFallWallJumpDirectionSpeed, pfNode, followingPlayerScript, pathfindingGameObjectSize); }
private void OnSceneGUI() { PathFindingData pfData = (PathFindingData)target; FollowingPlayer followingPlayerScript = pfData.pathfindingGameObject.GetComponent <FollowingPlayer>(); Vector3 pathfindingGameObjectSize = pfData.pathfindingGameObject.transform.lossyScale; foreach (PathFindingNode pfNode in pfData.pathFindingNodes) { pfNode.objectOnFromPlatformY = pfData.CalculateGameObjectOnPlatformY(pfNode.platformGameObject, pfData.pathfindingGameObject); if (!pfNode.showConnectionHandles) { continue; } Handles.color = Color.green; Handles.DrawWireCube(pfNode.platformGameObject.transform.position, pfNode.platformGameObject.transform.lossyScale); foreach (ConnectedNode cNode in pfNode.connectedNodes) { cNode.objectOnFromPlatformY = pfNode.objectOnFromPlatformY; cNode.objectOnToPlatformY = pfData.CalculateGameObjectOnPlatformY(cNode.platformGameObject, pfData.pathfindingGameObject); if (!cNode.showConnectionHandles) { continue; } Handles.color = Color.blue; Handles.DrawWireCube(cNode.platformGameObject.transform.position, cNode.platformGameObject.transform.lossyScale); Handles.color = Color.red; switch (cNode.connectionType) { case ConnectedNode.ConnectionType.Jump: JumpConnection(pfNode, cNode, followingPlayerScript, pathfindingGameObjectSize); break; case ConnectedNode.ConnectionType.Fall: FallConnection(pfData, pfNode, cNode, followingPlayerScript, pathfindingGameObjectSize); break; case ConnectedNode.ConnectionType.JumpWallJump: JumpWallJumpConnection(pfNode, cNode, followingPlayerScript, pathfindingGameObjectSize); break; case ConnectedNode.ConnectionType.FallWallJump: FallWallJumpConnection(pfData, pfNode, cNode, followingPlayerScript, pathfindingGameObjectSize); break; } } } }
private void FallConnection(PathFindingData pfData, PathFindingNode pfNode, ConnectedNode cNode, FollowingPlayer followingPlayerScript, Vector3 pathfindingGameObjectSize) { if (cNode.fallDirectionSpeed > followingPlayerScript.maxSpeed) { cNode.fallDirectionSpeed = followingPlayerScript.maxSpeed; } else if (cNode.fallDirectionSpeed < -followingPlayerScript.maxSpeed) { cNode.fallDirectionSpeed = -followingPlayerScript.maxSpeed; } cNode.fallStartX = pfNode.platformGameObject.transform.position.x + (pfNode.platformGameObject.transform.lossyScale.x / 2 + pfData.pathfindingGameObject.transform.lossyScale.x / 2) * (cNode.fallDirectionSpeed > 0 ? 1 : -1); cNode.onPlatformValue = 1; if (cNode.objectOnToPlatformY < pfNode.objectOnFromPlatformY) { cNode.onPlatformValue = followingPlayerScript.CalculateXFromYInFall(cNode.objectOnToPlatformY - pfNode.objectOnFromPlatformY); } FallVisualization(cNode.onPlatformValue, cNode.fallStartX, cNode.fallDirectionSpeed, pfNode, cNode, followingPlayerScript, pathfindingGameObjectSize); }
private MoveT[] TracePath(Dictionary <Node, PathFindingData> pathfindingData, Node endNode) { Node currentNode = endNode; PathFindingData currentData = pathfindingData[currentNode]; List <Node> path = new List <Node>(); int safetyCheck = 100; while (currentData.Parent != null) { if (safetyCheck-- < 0) { throw new Exception("Infinite Loop"); } path.Add(currentNode); currentNode = currentData.Parent; currentData = pathfindingData[currentNode]; } path.Add(currentNode); path.Reverse(); List <MoveT> moves = new List <MoveT>(); for (int i = 0; i < path.Count - 1; i++) { moves.Add(path[i].GetNeighbour(path[i + 1]).Move); } List <string> nodeNames = new List <string>(); foreach (var p in moves) { nodeNames.Add(p.ToString()); } //Debug.Log($"{path.Count} nodes in path [{string.Join(" -> ", nodeNames)}]"); return(moves.ToArray()); }
private void SetToStop(ref PathFindingData pathFinding, Translation translation) { pathFinding.decidedGoal = translation.Value; pathFinding.radius = 1f; }
private DecidedGoalType DecidedGoal(GroupCondition group, Condition condition, Translation translation, ref PathFindingData pathFindingData) { if (!condition.isSet) { if (!group.isSet) { return(DecidedGoalType.None); } return(DecidedGoalType.Group); } if (!group.isSet) { return(DecidedGoalType.Condition); } var conditionDistance = math.length(condition.goal - translation.Value); var groupDistance = math.length(group.goal - translation.Value); switch (pathFindingData.decisionMethod) { case DecisionMethod.Max: if (conditionDistance < groupDistance) { return(DecidedGoalType.Group); } else { return(DecidedGoalType.Condition); } case DecisionMethod.Min: if (conditionDistance < groupDistance) { return(DecidedGoalType.Condition); } else { return(DecidedGoalType.Group); } case DecisionMethod.ConditionOverGroup: return(DecidedGoalType.Condition); case DecisionMethod.GroupOverCondition: return(DecidedGoalType.Group); } return(DecidedGoalType.None); }
public void SetPathFindingData(PathFindingData pathFindingData) { _pathFindingData = pathFindingData; }