private IEnumerator DoFallWallJumpCoroutine(ConnectedNode connectedNode) { yield return(DoFallCoroutine(connectedNode, connectedNode.fallWallJumpStartX, connectedNode.preFallWallJumpDirectionSpeed)); Vector2 wallJumpStarPos = new Vector2(connectedNode.firstFallWallJumpHit.x, connectedNode.fallWallJumpY); yield return(GoToPositionCoroutine(wallJumpStarPos)); yield return(DoJumpCoroutine(connectedNode, wallJumpStarPos.x, connectedNode.fallWallJumpY, connectedNode.postFallWallJumpDirectionSpeed, connectedNode.onPlatformValue2)); }
private IEnumerator DoJumpWallJumpCoroutine(ConnectedNode connectedNode) { yield return(DoJumpCoroutine(connectedNode, connectedNode.preJumpWallJumpStartX, connectedNode.objectOnFromPlatformY, connectedNode.preJumpWallJumpDirectionSpeed, connectedNode.onPlatformValue)); Vector2 wallJumpStartPos = new Vector2(connectedNode.firstJumpWallJumpHit.x, connectedNode.jumpWallJumpY); yield return(GoToPositionCoroutine(wallJumpStartPos)); yield return(DoJumpCoroutine(connectedNode, connectedNode.firstJumpWallJumpHit.x, connectedNode.jumpWallJumpY, connectedNode.postJumpWallJumpDirectionSpeed, connectedNode.onPlatformValue2)); }
private void JumpWallJumpConnection(PathFindingNode pfNode, ConnectedNode cNode, FollowingPlayer followingPlayerScript, Vector3 pathfindingGameObjectSize) { if (cNode.preJumpWallJumpDirectionSpeed > followingPlayerScript.maxSpeed) { cNode.preJumpWallJumpDirectionSpeed = followingPlayerScript.maxSpeed; } else if (cNode.preJumpWallJumpDirectionSpeed < -followingPlayerScript.maxSpeed) { cNode.preJumpWallJumpDirectionSpeed = -followingPlayerScript.maxSpeed; } Vector2 jumpWallJumpPlatformSizeDiv2 = cNode.jumpWallJumpPlatform.transform.lossyScale / 2f; Vector2 jumpWallJumpPlatformPos = cNode.jumpWallJumpPlatform.transform.position; cNode.firstJumpWallJumpHit.x = jumpWallJumpPlatformPos.x + (jumpWallJumpPlatformSizeDiv2.x + pathfindingGameObjectSize.x / 2f) * (cNode.preJumpWallJumpDirectionSpeed > 0f ? -1f : 1f); cNode.onPlatformValue = Math.Abs((cNode.firstJumpWallJumpHit.x - cNode.preJumpWallJumpStartX) / cNode.preJumpWallJumpDirectionSpeed); cNode.firstJumpWallJumpHit.y = pfNode.objectOnFromPlatformY + followingPlayerScript.CalculateJumpY(cNode.onPlatformValue); if (cNode.firstJumpWallJumpHit.y < jumpWallJumpPlatformPos.y - jumpWallJumpPlatformSizeDiv2.y || cNode.firstJumpWallJumpHit.y > jumpWallJumpPlatformPos.y + jumpWallJumpPlatformSizeDiv2.y || cNode.preJumpWallJumpDirectionSpeed == 0f) { cNode.onPlatformValue = 1; } JumpVisualization(cNode.onPlatformValue, cNode.preJumpWallJumpStartX, pfNode.objectOnFromPlatformY, cNode.preJumpWallJumpDirectionSpeed, pfNode, followingPlayerScript, pathfindingGameObjectSize); if (cNode.jumpWallJumpY > cNode.firstJumpWallJumpHit.y) { cNode.jumpWallJumpY = cNode.firstJumpWallJumpHit.y; } else if (cNode.jumpWallJumpY < jumpWallJumpPlatformPos.y - jumpWallJumpPlatformSizeDiv2.y) { cNode.jumpWallJumpY = jumpWallJumpPlatformPos.y - jumpWallJumpPlatformSizeDiv2.y; } StraightFallVisualization(cNode.firstJumpWallJumpHit.y, cNode.jumpWallJumpY, cNode.firstJumpWallJumpHit.x, pathfindingGameObjectSize); if (cNode.postJumpWallJumpDirectionSpeed > followingPlayerScript.maxSpeed) { cNode.postJumpWallJumpDirectionSpeed = followingPlayerScript.maxSpeed; } else if (cNode.postJumpWallJumpDirectionSpeed < -followingPlayerScript.maxSpeed) { cNode.postJumpWallJumpDirectionSpeed = -followingPlayerScript.maxSpeed; } cNode.onPlatformValue2 = 1; if (cNode.objectOnToPlatformY <= cNode.jumpWallJumpY + followingPlayerScript.jumpHeight) { cNode.onPlatformValue2 = followingPlayerScript.CalculateXFromYInJump(cNode.objectOnToPlatformY - cNode.jumpWallJumpY); } JumpVisualization(cNode.onPlatformValue2, cNode.firstJumpWallJumpHit.x, cNode.jumpWallJumpY, cNode.postJumpWallJumpDirectionSpeed, pfNode, followingPlayerScript, pathfindingGameObjectSize); }
protected override void OnDragFinish() { ConnectedNode node = (SelectionManager.Instance.HoverNode as ConnectedNode); if (node) { if (node != this) { currentDraggingLine.EndPoint = node.transform.position; currentDraggingLine = null; return; } } Destroy(currentGameObject); currentDraggingLine = null; }
private void JumpConnection(PathFindingNode pfNode, ConnectedNode cNode, FollowingPlayer followingPlayerScript, Vector3 pathfindingGameObjectSize) { if (cNode.jumpDistance > followingPlayerScript.maxSpeed) { cNode.jumpDistance = followingPlayerScript.maxSpeed; } else if (cNode.jumpDistance < -followingPlayerScript.maxSpeed) { cNode.jumpDistance = -followingPlayerScript.maxSpeed; } cNode.onPlatformValue = 1; if (cNode.objectOnToPlatformY <= pfNode.objectOnFromPlatformY + followingPlayerScript.jumpHeight) { cNode.onPlatformValue = followingPlayerScript.CalculateXFromYInJump(cNode.objectOnToPlatformY - pfNode.objectOnFromPlatformY); } JumpVisualization(cNode.onPlatformValue, cNode.jumpStartX, pfNode.objectOnFromPlatformY, cNode.jumpDistance, pfNode, followingPlayerScript, pathfindingGameObjectSize); }
private IEnumerator DoJumpCoroutine(ConnectedNode connectedNode, float jumpStartX, float jumpStartY, float jumpDirectionSpeed, float onPlatformValue) { Vector3 startPos = new Vector3(jumpStartX, jumpStartY); if (transform.position != startPos) { yield return(GoToPositionCoroutine(startPos)); } float horizontalDistance = Math.Abs(onPlatformValue * jumpDirectionSpeed); float currentBetweenPoint = 0f; while (currentBetweenPoint < onPlatformValue) { currentBetweenPoint = Math.Min(onPlatformValue, currentBetweenPoint + Math.Abs(jumpDirectionSpeed * Time.deltaTime / horizontalDistance)); transform.position = new Vector3(startPos.x + currentBetweenPoint * jumpDirectionSpeed, startPos.y + CalculateJumpY(currentBetweenPoint)); yield return(new WaitForEndOfFrame()); } }
private IEnumerator DoFallCoroutine(ConnectedNode connectedNode, float fallStartX, float fallDirectionSpeed) { Vector3 startPos = new Vector3(fallStartX, connectedNode.objectOnFromPlatformY); if (transform.position != startPos) { yield return(GoToPositionCoroutine(startPos)); } float horizontalDistance = Math.Abs(connectedNode.onPlatformValue * fallDirectionSpeed); float currentBetweenPoint = 0f; while (currentBetweenPoint < connectedNode.onPlatformValue) { currentBetweenPoint = Math.Min(connectedNode.onPlatformValue, currentBetweenPoint + Math.Abs(fallDirectionSpeed * Time.deltaTime / horizontalDistance)); transform.position = new Vector3(startPos.x + currentBetweenPoint * fallDirectionSpeed, startPos.y + CalculateFallY(currentBetweenPoint)); yield return(new WaitForEndOfFrame()); } }
protected override void OnReceiveProtocolError(ConnectedNode sender, string message) { base.OnReceiveProtocolError(sender, message); //get sender ip address IPAddress ipAddress = IPAddress.None; if (sender.RemoteEndPoint != null) { ipAddress = sender.RemoteEndPoint.Address; } string ipAddressText = ipAddress.ToString(); //use it for debugging //Log.Warning( "GameNetworkClient: Protocol error: {0} from \"{1}\".", message, ipAddressText ); DisconnectConnectedNode(sender, "Protocol error: " + message, 1); }
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 static Node CalculatePathNextNode(long callerId, ref NodeNetworkCopy network, ref Node startNode, ref Node endNode, Destination endDestination) { var openNodes = new List <ConnectedNode> { new ConnectedNode(endNode) }; var closedNodes = new List <ConnectedNode>(); ConnectedNode lastNode = null; var updateIndex = 0; while (true) { // propogate var thisNode = openNodes.First(); openNodes.Remove(thisNode); closedNodes.Add(thisNode); var neighbours = network.Links .Where(l => l.NodeA.Equals(thisNode) || l.NodeB.Equals(thisNode)) .Select(l => l.NodeA.Equals(thisNode) ? new ConnectedNode(l.NodeB) : new ConnectedNode(l.NodeA)) .ToList(); // calculate var foundEnd = false; foreach (var n in neighbours) { if (closedNodes.SingleOrDefault(cn => cn.Equals(n)) != null) { continue; } if (n.Equals(startNode)) { foundEnd = true; lastNode = n; } n.ConnectedTo = thisNode; n.Value = Math.Sqrt(Math.Pow((n.PositionX - startNode.PositionX), 2) + Math.Pow((n.PositionY - startNode.PositionY), 2)); network.Nodes.Single(nn => nn.Equals(n)).Value = n.Value; #if DEBUG AlgorithmDebuggerWindow.Instance.AddNodeUpdateResult($"AS{_debuggerIndex}${updateIndex++}", network, n, thisNode); #endif openNodes.Add(n); } if (foundEnd) { break; } // sort openNodes = openNodes.OrderBy(n => n.Value).ToList(); // info #if DEBUG AlgorithmDebuggerWindow.Instance.AddNetworkResult($"AS{_debuggerIndex}#{openNodes.First().Value}", network, thisNode, openNodes.First()); #endif } var roadX = (startNode.PositionX - lastNode.ConnectedTo.PositionX) / 2.0 + lastNode.ConnectedTo.PositionX; var roadY = (startNode.PositionY - lastNode.ConnectedTo.PositionY) / 2.0 + lastNode.ConnectedTo.PositionY; var result = new Destination { Location = new Vector(lastNode.ConnectedTo.PositionX, lastNode.ConnectedTo.PositionY), Road = GPSSystem.NearestRoad(new Vector(roadX, roadY)) }; if (_calculationCache.ContainsKey(callerId)) { _calculationCache.Remove(callerId); } _calculationCache.Add(callerId, new Tuple <Destination, List <ConnectedNode> >(endDestination, closedNodes)); // find next node return(lastNode.ConnectedTo); }
public bool ContainsNode(Node node) { return(ParentNode.Equals(node) || ConnectedNode.Equals(node)); }
protected override void OnReceiveProtocolError( ConnectedNode sender, string message ) { base.OnReceiveProtocolError( sender, message ); //get sender ip address IPAddress ipAddress = IPAddress.None; if( sender.RemoteEndPoint != null ) ipAddress = sender.RemoteEndPoint.Address; string ipAddressText = ipAddress.ToString(); //use it for debugging //Log.Warning( "GameNetworkClient: Protocol error: {0} from \"{1}\".", message, ipAddressText ); DisconnectConnectedNode( sender, "Protocol error: " + message, 1 ); }
private void FallVisualization(float onPlatformValue, float fallStartX, float fallDirectionSpeed, PathFindingNode pfNode, ConnectedNode cNode, FollowingPlayer followingPlayerScript, Vector3 pathfindingGameObjectSize) { float visualStep = 0.1f; for (float currentVisualStep = 0f; currentVisualStep < onPlatformValue; currentVisualStep += visualStep) { Handles.DrawWireCube( new Vector3(fallStartX + currentVisualStep * fallDirectionSpeed, pfNode.objectOnFromPlatformY + followingPlayerScript.CalculateFallY(currentVisualStep)), pathfindingGameObjectSize); } }
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 List <ConnectedNode> GenerateShortestPath(PathFindingNode startPathFindingNode, PathFindingNode goalPathFindingNode) { startPathFindingNode.FromStartCost = 0f; startPathFindingNode.ToGoalDistance = Vector2.Distance(startPathFindingNode.platformGameObject.transform.position, goalPathFindingNode.platformGameObject.transform.position) / maxSpeed; startPathFindingNode.Score = startPathFindingNode.ToGoalDistance; List <PathFindingNode> openNodes = new List <PathFindingNode>() { startPathFindingNode }; List <PathFindingNode> closedNodes = new List <PathFindingNode>(); PathFindingNode currentNode = new PathFindingNode(); foreach (PathFindingNode pfn in pathFindingData.pathFindingNodes) { pfn.CameFromNode = null; } { } while (openNodes.Count > 0) { currentNode = openNodes.Aggregate((i1, i2) => i1.Score < i2.Score ? i1 : i2); if (currentNode == goalPathFindingNode) { break; } openNodes.Remove(currentNode); closedNodes.Add(currentNode); foreach (ConnectedNode connection in currentNode.connectedNodes) { PathFindingNode connectedNode = pathFindingData.pathFindingNodes[FindPlatformIndexInPFData(connection.platformGameObject)]; if (closedNodes.Contains(connectedNode)) { continue; } float newFromStartCost = currentNode.FromStartCost + Vector2.Distance(currentNode.platformGameObject.transform.position, connectedNode.platformGameObject.transform.position); if (!openNodes.Contains(connectedNode) || newFromStartCost < connectedNode.FromStartCost) { connectedNode.FromStartCost = newFromStartCost; connectedNode.ToGoalDistance = Vector2.Distance(connectedNode.platformGameObject.transform.position, goalPathFindingNode.platformGameObject.transform.position); connectedNode.Score = connectedNode.FromStartCost + connectedNode.ToGoalDistance; connectedNode.CameFromNode = currentNode; if (!openNodes.Contains(connectedNode)) { openNodes.Add(connectedNode); } } } } //convert the found path into executable format List <ConnectedNode> reversePath = new List <ConnectedNode>(); while (currentNode.CameFromNode != null) { ConnectedNode connectionUsed = currentNode.CameFromNode.connectedNodes.Find(f => f.platformGameObject == currentNode.platformGameObject); reversePath.Add(connectionUsed); currentNode = currentNode.CameFromNode; } reversePath.Reverse(); return(reversePath); }
public override string ToString() { return("-> " + ConnectedNode.ToString()); }