From 71ca8d3357a2604969b736cdb8e2bb8a15d1aa06 Mon Sep 17 00:00:00 2001 From: Joa2 Date: Tue, 9 Apr 2024 16:20:05 +0200 Subject: [PATCH] =?UTF-8?q?angefangen=20pathfinding=20zu=20=C3=BCberabreit?= =?UTF-8?q?en.=20funktioniert=20noch=20nicht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Client/menues/LoginPlayerMenu.gd | 1 + Client/region/Region.gd | 283 +++++++++++++++++++------------ Client/region/SuperUnit.gd | 12 -- Client/region/Unit.gd | 12 -- Server/new_script.vs | Bin 0 -> 320 bytes Server/region/Region.gd | 14 +- 6 files changed, 181 insertions(+), 141 deletions(-) create mode 100644 Server/new_script.vs diff --git a/Client/menues/LoginPlayerMenu.gd b/Client/menues/LoginPlayerMenu.gd index 28f495f..9f7b781 100644 --- a/Client/menues/LoginPlayerMenu.gd +++ b/Client/menues/LoginPlayerMenu.gd @@ -7,6 +7,7 @@ func _on_btnBack_button_down(): func _on_btnRegister_button_down(): PlayerManager.logInUser(username, password) + get_tree().change_scene("res://region/Region.tscn") func _on_iptPlayerName_text_changed(new_text): username = new_text diff --git a/Client/region/Region.gd b/Client/region/Region.gd index d0911e2..9e86a13 100644 --- a/Client/region/Region.gd +++ b/Client/region/Region.gd @@ -12,7 +12,7 @@ var selectedFaction var boardUnits ={} var occupiedTiles=[] var enemyOccupiedTiles=[] -var route +var stepsStartToTileInCoords var routeVertices var hoveredCoords var regionID = 123 @@ -39,7 +39,7 @@ func receiveTiles(newTileRect, newTiles, newSuperTiles): func requestUnits(): WorldManager.requestUnits(regionID) -func receiveUnits(newBoardUnits):#overwork this +func receiveUnits(newBoardUnits): boardUnits = newBoardUnits for child in $TileMap/Units.get_children(): child.queue_free() @@ -55,31 +55,22 @@ func receiveUnits(newBoardUnits):#overwork this newUnit.on_ready() boardUnitsIndex +=1 -func unitSelectedMethod(unit, debugOriginUnit):#this is called when a unit is selected - print("from: ",boardUnits[debugOriginUnit.boardUnitsIndex].id) - if unit == null: - clearPathingInfo() - $moveapcost.text = "" - $unitapcounter.text = "" - selectedFaction = null - selectedUnit = null - for unit in boardUnits: - unit.isSelected = false - $TileMap/LineManager.drawAdvancedLine([],[],0,0) - else: - selectedNode = unit - selectedUnit = boardUnits[unit.boardUnitsIndex] - requestTiles(selectedUnit) - selectedFaction = selectedUnit.faction - for unit in boardUnits: - if unit.id != selectedUnit.id: - unit.isSelected = false - $TileMap/LineManager.drawAdvancedLine([],[],0,0) -# print(selectedUnit) - func _input(event):#this responds to any input. Has various functions depending on input - if selectedUnit != null: - if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"): + if event is InputEventMouse: + mouseEvent(event) + if event is InputEvent and Input.is_action_just_released("ui_accept"): + if animationInProgress == false: + nextRound() + if event is InputEvent and Input.is_action_just_released("ui_right"): + print("reset pathing") + resetPathing() + +func mouseEvent(event): + if !selectedUnit: + if Input.is_action_just_released("ui_left_mouse_button"): + pass + else: + if Input.is_action_just_released("ui_left_mouse_button"): if !selectedUnit.superUnit: clickPath() else: @@ -91,27 +82,21 @@ func _input(event):#this responds to any input. Has various functions depending hoverPath() else: hoverSuperPath() - if event is InputEvent and Input.is_action_just_released("ui_accept"): - if animationInProgress == false: - nextRound() - if event is InputEvent and Input.is_action_just_released("ui_right"): - print("reset pathing") - resetPathing() func clickPath():#this finalizes the selected path while calculating ap and new ap and shortening the path if ap is insufficient. Then it calls to execute the path - if animationInProgress == false and route.size() >1: + if animationInProgress == false and stepsStartToTileInCoords.size() >1: var totalApCost = addUpArray(routeVertices) if totalApCost > selectedUnit.moveAp: var apDebt = totalApCost - selectedUnit.moveAp if apDebt > selectedUnit.ap: while addUpArray(routeVertices) > selectedUnit.ap + selectedUnit.moveAp: - route.pop_back() + stepsStartToTileInCoords.pop_back() routeVertices.pop_back() - while route.size() != 0 and occupiedTiles.has(route[-1]):#prevents overlap - route.pop_back() + while stepsStartToTileInCoords.size() != 0 and occupiedTiles.has(stepsStartToTileInCoords[-1]):#prevents overlap + stepsStartToTileInCoords.pop_back() routeVertices.pop_back() - if route.size() > 1: - executePath(route, routeVertices) + if stepsStartToTileInCoords.size() > 1: + executePath(stepsStartToTileInCoords, routeVertices) func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the pathfinding to make the path and tells the line to draw the returned path if selectedUnit !=null and coord != null: @@ -132,11 +117,10 @@ func nextRound():#this sends a nextRound signal to units on the board and refres WorldManager.endTurn(regionID) WorldManager.requestUnits(regionID) - -func executePath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. - WorldManager.requestMove(route,selectedUnit.id, regionID) +func executePath(stepsStartToTileInCoords, stepsStartToTileInDistances):#this takes the current selected stepsStartToTileInCoords and tells the unit to execute it/ follow the selected stepsStartToTileInCoords. + WorldManager.requestMove(stepsStartToTileInCoords,selectedUnit.id, regionID) var convertedRoute = [] - for coords in route: + for coords in stepsStartToTileInCoords: convertedRoute.append($TileMap.map_to_world(coords)) selectedNode.moveOnPath(convertedRoute) animationInProgress = true @@ -145,44 +129,44 @@ func executePath(route, vertices):#this takes the current selected route and tel func clearPathingInfo():#this erases the Dijkstra/pathfinding-specific tile info for when a new tile is selected and new pathfinding info is needed. for column in tiles: for tile in column: - tile.verticeExplored = false - tile.route = [] + tile.surroundingTilesExplored = false + tile.stepsStartToTileInCoords = [] tile.shortestKnownPath = INF - tile.vertices = [] + tile.stepsStartToTileInDistances = [] for column in superTiles: for tile in column: - tile.verticeExplored = false - tile.route = [] + tile.surroundingTilesExplored = false + tile.stepsStartToTileInCoords = [] tile.shortestKnownPath = INF - tile.vertices = [] + tile.stepsStartToTileInDistances = [] pass func setDistance(target, origin, index, diagonal = false):#this sets the distances to the connections between tiles. if not diagonal: match target.type: "grass": - origin.verticeDistance[index] = 5 + origin.distancesToSurroundingTiles[index] = 5 "road": - origin.verticeDistance[index] = 2 + origin.distancesToSurroundingTiles[index] = 2 "mountain": - origin.verticeDistance[index] = INF + origin.distancesToSurroundingTiles[index] = INF "enemyOccupied": - origin.verticeDistance[index] = INF + origin.distancesToSurroundingTiles[index] = INF else: match target.type: "grass": - origin.verticeDistance[index] = 8 + origin.distancesToSurroundingTiles[index] = 8 "road": - origin.verticeDistance[index] = 3 + origin.distancesToSurroundingTiles[index] = 3 "mountain": - origin.verticeDistance[index] = INF + origin.distancesToSurroundingTiles[index] = INF "enemyOccupied": - origin.verticeDistance[index] = INF + origin.distancesToSurroundingTiles[index] = INF -func findPath(start, end):#this actually finds the path. returns an array that at [0] contains the route and at [1] contains the distances of each step on the route (vertices). +func findPath(start, end):#this actually finds the path. returns an array that at [0] contains the stepsStartToTileInCoords and at [1] contains the distances of each step on the stepsStartToTileInCoords (stepsStartToTileInDistances). var startingTile = tiles[start.x][start.y] var endTile = tiles[end.x][end.y] - startingTile.vertices = [0] + startingTile.stepsStartToTileInDistances = [0] var smallestVerticeDistance var a = [1] for number in a: @@ -190,28 +174,28 @@ func findPath(start, end):#this actually finds the path. returns an array that a var smallestVertice = [INF] for columns in tiles: for tile in columns: - if tile.route.size() == 0: - tile.route.append(startingTile.coords) - if tile.vertices == null: - print("\n ERROR Some vertices are null \n") + if tile.stepsStartToTileInCoords.size() == 0: + tile.stepsStartToTileInCoords.append(startingTile.coords) + if tile.stepsStartToTileInDistances == null: + print("\n ERROR Some stepsStartToTileInDistances are null \n") break - if tile.verticeExplored == false and tile.vertices.size() > 0: + if tile.surroundingTilesExplored == false and tile.stepsStartToTileInDistances.size() > 0: smallestVerticeDistance = addUpArray(smallestVertice) var tileTotalVertice = 0 - tileTotalVertice = addUpArray(tile.vertices) + tileTotalVertice = addUpArray(tile.stepsStartToTileInDistances) if tileTotalVertice < smallestVerticeDistance: - smallestVertice = tile.vertices - currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten Vertices/ dem kurzesten Pfad + smallestVertice = tile.stepsStartToTileInDistances + currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten stepsStartToTileInDistances/ dem kurzesten Pfad if currentTile == null: animationInProgress = false break if currentTile == endTile: - route=endTile.route - routeVertices=endTile.vertices - return[endTile.route, endTile.vertices] + stepsStartToTileInCoords=endTile.stepsStartToTileInCoords + routeVertices=endTile.stepsStartToTileInDistances + return[endTile.stepsStartToTileInCoords, endTile.stepsStartToTileInDistances] var translation = null var direction = 0 - for entry in currentTile.verticeDistance: + for entry in currentTile.distancesToSurroundingTiles: match direction: 0: if entry != INF: @@ -239,17 +223,17 @@ func findPath(start, end):#this actually finds the path. returns an array that a translation = Vector2(-1,1) if translation != null: var tileToModify = tiles[(currentTile.coords + translation).x][(currentTile.coords + translation).y] - if addUpArray(currentTile.vertices) + currentTile.verticeDistance[direction] < addUpArray(tileToModify.vertices) or tileToModify.vertices.size() == 0: + if addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction] < addUpArray(tileToModify.stepsStartToTileInDistances) or tileToModify.stepsStartToTileInDistances.size() == 0: # print("Shorter Path found.") - var newShortestPath = currentTile.duplicate().vertices.duplicate() - var newnewShortestPath = newShortestPath.append(currentTile.duplicate().verticeDistance.duplicate()[direction]) - tileToModify.vertices = newShortestPath.duplicate() - var newShortestRoute = currentTile.duplicate().route.duplicate() + var newShortestPath = currentTile.duplicate().stepsStartToTileInDistances.duplicate() + var newnewShortestPath = newShortestPath.append(currentTile.duplicate().distancesToSurroundingTiles.duplicate()[direction]) + tileToModify.stepsStartToTileInDistances = newShortestPath.duplicate() + var newShortestRoute = currentTile.duplicate().stepsStartToTileInCoords.duplicate() var newnewShortestRoute = newShortestRoute.append(tileToModify.coords) #this is really bodged but i dont know how to fix it and it somehow works fine despite everything - tileToModify.route = newShortestRoute + tileToModify.stepsStartToTileInCoords = newShortestRoute direction += 1 tiles[currentTile.coords.x][currentTile.coords.y]= currentTile - currentTile.verticeExplored = true + currentTile.surroundingTilesExplored = true a.append(1) func addUpArray(array):#adds up each int in an array. useful for calculating total distance. @@ -266,18 +250,18 @@ func _on_pathAnimationCompleted():#this gets a signal from the selected unit and animationInProgress = false selectedUnit = null -func resetPathing():#this clears the current route and removes the line. Without it weird bugs can happen where It can do a path that it already did again. - route = [] +func resetPathing():#this clears the current stepsStartToTileInCoords and removes the line. Without it weird bugs can happen where It can do a path that it already did again. + stepsStartToTileInCoords = [] routeVertices = [] if selectedUnit != null: - $TileMap/LineManager.drawAdvancedLine(route, routeVertices, selectedUnit.ap, selectedUnit.moveAp) + $TileMap/LineManager.drawAdvancedLine(stepsStartToTileInCoords, routeVertices, selectedUnit.ap, selectedUnit.moveAp) else: - $TileMap/LineManager.drawAdvancedLine(route, routeVertices, 0, 0) + $TileMap/LineManager.drawAdvancedLine(stepsStartToTileInCoords, routeVertices, 0, 0) func findSuperPath(start,end): var startingTile = superTiles[start.x][start.y] var endTile = superTiles[end.x][end.y] - startingTile.vertices = [0] + startingTile.stepsStartToTileInDistances = [0] var smallestVerticeDistance var a = [1] for number in a: @@ -285,28 +269,28 @@ func findSuperPath(start,end): var smallestVertice = [INF] for columns in superTiles: for tile in columns: - if tile.route.size() == 0: - tile.route.append(startingTile.coords) - if tile.vertices == null: - print("\n ERROR Some vertices are null \n") + if tile.stepsStartToTileInCoords.size() == 0: + tile.stepsStartToTileInCoords.append(startingTile.coords) + if tile.stepsStartToTileInDistances == null: + print("\n ERROR Some stepsStartToTileInDistances are null \n") break - if tile.verticeExplored == false and tile.vertices.size() > 0: + if tile.surroundingTilesExplored == false and tile.stepsStartToTileInDistances.size() > 0: smallestVerticeDistance = addUpArray(smallestVertice) var tileTotalVertice = 0 - tileTotalVertice = addUpArray(tile.vertices) + tileTotalVertice = addUpArray(tile.stepsStartToTileInDistances) if tileTotalVertice < smallestVerticeDistance: - smallestVertice = tile.vertices - currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten Vertices/ dem kurzesten Pfad + smallestVertice = tile.stepsStartToTileInDistances + currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten stepsStartToTileInDistances/ dem kurzesten Pfad if currentTile == null: animationInProgress = false break if currentTile == endTile: - route=endTile.route - routeVertices=endTile.vertices - return[endTile.route, endTile.vertices] + stepsStartToTileInCoords=endTile.stepsStartToTileInCoords + routeVertices=endTile.stepsStartToTileInDistances + return[endTile.stepsStartToTileInCoords, endTile.stepsStartToTileInDistances] var translation = null var direction = 0 - for entry in currentTile.verticeDistance: + for entry in currentTile.distancesToSurroundingTiles: match direction: 0: if entry != INF: @@ -334,17 +318,17 @@ func findSuperPath(start,end): translation = Vector2(-1,1) if translation != null: var tileToModify = superTiles[(currentTile.coords + translation).x][(currentTile.coords + translation).y] - if addUpArray(currentTile.vertices) + currentTile.verticeDistance[direction] < addUpArray(tileToModify.vertices) or tileToModify.vertices.size() == 0: + if addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction] < addUpArray(tileToModify.stepsStartToTileInDistances) or tileToModify.stepsStartToTileInDistances.size() == 0: # print("Shorter Path found.") - var newShortestPath = currentTile.duplicate().vertices.duplicate() - var newnewShortestPath = newShortestPath.append(currentTile.duplicate().verticeDistance.duplicate()[direction]) - tileToModify.vertices = newShortestPath.duplicate() - var newShortestRoute = currentTile.duplicate().route.duplicate() + var newShortestPath = currentTile.duplicate().stepsStartToTileInDistances.duplicate() + var newnewShortestPath = newShortestPath.append(currentTile.duplicate().distancesToSurroundingTiles.duplicate()[direction]) + tileToModify.stepsStartToTileInDistances = newShortestPath.duplicate() + var newShortestRoute = currentTile.duplicate().stepsStartToTileInCoords.duplicate() var newnewShortestRoute = newShortestRoute.append(tileToModify.coords) #this is really bodged but i dont know how to fix it and it somehow works fine despite everything - tileToModify.route = newShortestRoute + tileToModify.stepsStartToTileInCoords = newShortestRoute direction += 1 superTiles[currentTile.coords.x][currentTile.coords.y]= currentTile - currentTile.verticeExplored = true + currentTile.surroundingTilesExplored = true a.append(1) func hoverSuperPath(coord = hoveredCoords): @@ -361,20 +345,103 @@ func hoverSuperPath(coord = hoveredCoords): $TileMap/LineManager.drawAdvancedSuperLine(path[0], path[1], selectedUnit.ap, selectedUnit.moveAp) func clickSuperPath(): - if animationInProgress == false and route.size() >1: + if animationInProgress == false and stepsStartToTileInCoords.size() >1: var totalApCost = addUpArray(routeVertices) if totalApCost > selectedUnit.moveAp: var apDebt = totalApCost - selectedUnit.moveAp if apDebt > selectedUnit.ap: # print("Not enough AP for this move.") while addUpArray(routeVertices) > selectedUnit.ap + selectedUnit.moveAp: - route.pop_back() + stepsStartToTileInCoords.pop_back() routeVertices.pop_back() - while route.size() != 0 and (occupiedTiles.has(route[-1]) == true or occupiedTiles.has(route[-1]+Vector2(1,0)) == true or occupiedTiles.has(route[-1]+Vector2(0,1)) == true or occupiedTiles.has(route[-1]+Vector2(1,1)) == true):#prevents overlap - route.pop_back() + while stepsStartToTileInCoords.size() != 0 and (occupiedTiles.has(stepsStartToTileInCoords[-1]) == true or occupiedTiles.has(stepsStartToTileInCoords[-1]+Vector2(1,0)) == true or occupiedTiles.has(stepsStartToTileInCoords[-1]+Vector2(0,1)) == true or occupiedTiles.has(stepsStartToTileInCoords[-1]+Vector2(1,1)) == true):#prevents overlap + stepsStartToTileInCoords.pop_back() routeVertices.pop_back() - if route.size() != 0 and route[0] != route[-1]: + if stepsStartToTileInCoords.size() != 0 and stepsStartToTileInCoords[0] != stepsStartToTileInCoords[-1]: totalApCost = addUpArray(routeVertices) apDebt = totalApCost - selectedUnit.moveAp - if route.size() > 1: - executePath(route, routeVertices) + if stepsStartToTileInCoords.size() > 1: + executePath(stepsStartToTileInCoords, routeVertices) + + + + +func findPathFromCoordToCoord(coord1, coord2, tiles): + var startingTile = tiles[coord1.x][coord1.y] + var endTile = tiles[coord2.x][coord2.y] + startingTile.stepsStartToTileInDistances = [0, ] + for columns in tiles: + for tile in columns: + tile.stepsStartToTileInCoords = [startingTile.coords,] + var shortestPathDistance #smallestVerticeDistance + + var shortestPathFound = false + while !shortestPathFound: + var currentTile = null #The unexplored Tile with the shortest Path + + + #Selects next currentTile / Tile with shortest path to it + for columns in tiles: + for tile in columns: + if tile.surroundingTilesExplored == false and tile.stepsStartToTileInDistances.size() > 0: + if addUpArray(tile.stepsStartToTileInDistances) < shortestPathDistance: + shortestPathDistance = addUpArray(tile.stepsStartToTileInDistances) + currentTile = tile + + + #Checks whether the search is completed + if currentTile == endTile: + stepsStartToTileInCoords=endTile.stepsStartToTileInCoords + routeVertices=endTile.stepsStartToTileInDistances + shortestPathFound = true + return[endTile.stepsStartToTileInCoords, endTile.stepsStartToTileInDistances] + + + #Explore surrounding Tiles. Add the path taken to reach them via the current Tile if it is the shortest current path or the first. + var translation = null + var direction = 0 + for entry in currentTile.distancesToSurroundingTiles: + match direction: + 0: + if entry != INF: + translation = Vector2(0,1) + 1: + if entry != INF: + translation = Vector2(1,1) + 2: + if entry != INF: + translation = Vector2(1,0) + 3: + if entry != INF: + translation = Vector2(1,-1) + 4: + if entry != INF: + translation = Vector2(0,-1) + 5: + if entry != INF: + translation = Vector2(-1,-1) + 6: + if entry != INF: + translation = Vector2(-1,0) + 7: + if entry != INF: + translation = Vector2(-1,1) + + if translation != null: + var surroundingTile = tiles[(currentTile.coords + translation).x][(currentTile.coords + translation).y] + if (addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction]) < addUpArray(surroundingTile.stepsStartToTileInDistances): + pass + surroundingTile.stepsStartToTileInDistances.append() + surroundingTile.stepsStartToTileInCoords.append() + + + if addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction] < addUpArray(surroundingTile.stepsStartToTileInDistances) or surroundingTile.stepsStartToTileInDistances.size() == 0: + var newShortestPath = currentTile.duplicate().stepsStartToTileInDistances.duplicate() + var newnewShortestPath = newShortestPath.append(currentTile.duplicate().distancesToSurroundingTiles.duplicate()[direction]) + surroundingTile.stepsStartToTileInDistances = newShortestPath.duplicate() + var newShortestRoute = currentTile.duplicate().stepsStartToTileInCoords.duplicate() + var newnewShortestRoute = newShortestRoute.append(surroundingTile.coords) #this is really bodged but i dont know how to fix it and it somehow works fine despite everything + surroundingTile.stepsStartToTileInCoords = newShortestRoute + direction += 1 + currentTile.surroundingTilesExplored = true + return diff --git a/Client/region/SuperUnit.gd b/Client/region/SuperUnit.gd index f9e0624..eb795b2 100644 --- a/Client/region/SuperUnit.gd +++ b/Client/region/SuperUnit.gd @@ -3,14 +3,12 @@ extends Sprite signal positionReached var Route signal pathAnimationCompleted -signal unitSelected(unit) var isSelected = false var isMoving = false var boardUnitsIndex onready var region = get_parent().get_parent().get_parent() func on_ready():#this connects the unit to the main node using signals - connect("unitSelected",region, "unitSelectedMethod") connect("pathAnimationCompleted",region, "_on_pathAnimationCompleted") snapToPosition() if region.boardUnits[boardUnitsIndex].faction == "enemyFaction": @@ -29,16 +27,6 @@ func snapToPosition(): # unitCurrentUndertiles = undertiles pass -func _input(event):#this selects unit and signals the selected node to the main node - if event is InputEventMouseButton and Input.is_action_pressed("ui_right_mouse_button")and isMoving==false: - var localEvent = (self.make_input_local(event)) - if isSelected== true: -# emit_signal("unitSelected",null,self) - isSelected = false - elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64: - emit_signal("unitSelected",self,self) - isSelected = true - func moveOnPath(route:Array):#this coordinates the movement/animation isMoving=true var indexPosition = 0 diff --git a/Client/region/Unit.gd b/Client/region/Unit.gd index 6237dad..2923c2c 100644 --- a/Client/region/Unit.gd +++ b/Client/region/Unit.gd @@ -3,14 +3,12 @@ extends Sprite signal positionReached var Route signal pathAnimationCompleted -signal unitSelected(unit) var isSelected = false var isMoving = false var boardUnitsIndex onready var region = get_parent().get_parent().get_parent() func on_ready():#this connects the unit to the main node using signals - connect("unitSelected",region, "unitSelectedMethod") connect("pathAnimationCompleted",region, "_on_pathAnimationCompleted") snapToPosition() if region.boardUnits[boardUnitsIndex].faction == "enemyFaction": @@ -22,16 +20,6 @@ func on_ready():#this connects the unit to the main node using signals func snapToPosition(): self.position = get_parent().get_parent().map_to_world(region.boardUnits[boardUnitsIndex].coords) -func _input(event):#this selects unit and signals the selected node to the main node - if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false: - var localEvent = (self.make_input_local(event)) - if isSelected == true: -# emit_signal("unitSelected",null,self) Problem here ist das weil signale asynchron sind es mehrere units gibt die meinen is Selected wäre true und dan je nach layer der units, eine das selectunit(null) signal schickt, nachdem die anderen ihr selectunit(self) signal schickt und so null selektiert wird. Lösungen: Call statt Signal. Deselect funktion funktion in der diesem Script selbst ausführen. - isSelected = false - elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64: - emit_signal("unitSelected",self,self) - isSelected = true - func moveOnPath(route:Array):#this coordinates the movement/animation isMoving=true var indexPosition = 0 diff --git a/Server/new_script.vs b/Server/new_script.vs new file mode 100644 index 0000000000000000000000000000000000000000..e07a0f0a8dd81bec5ef684e34721a396c1ffe0d9 GIT binary patch literal 320 zcmV-G0l)rIQ$s@n000005C8y70ssIg0RR9fwJ-f(Oab)>0Fn(YE`UqY7&9;fFp&`% z5zre6*(1M6T6RB?WN*~II9vwUAk^sK!p-7-+$A