public Vector2[] CalcPath(Vector2 start, Vector2 end) { var curPath = pathmaker.GetSimplePath(start, end, true); var testPath = pathmaker.GetSimplePath(start, pathmaker.GetClosestPoint(end), true); if (end != pathmaker.GetClosestPoint(end)) { end.x = end.x + 0.01f; } bool optiChoice = true; return(pathmaker.GetSimplePath(start, end, optiChoice)); }
private void SetNavigationPath() { var pathArray = NavigationMap.GetSimplePath(OwnerMob.Position, TargetMob.Position, false); Path = new List <Vector2>(pathArray); DebugPathLine.Points = pathArray; }
// Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(float delta) { if (Input.GetMouseButtonMask() == 1) { PlayerToken.SetTarget(navigation.GetSimplePath(PlayerToken.Position, GetGlobalMousePosition())); } }
private void OnSpawn() { var path = _navigagtion.GetSimplePath(_spawner.GlobalPosition, _targer.GlobalPosition, false); var enemy = (Enemy)_enemyFactory[EnemyType.RegularSoldier].Instance(); enemy.GlobalPosition = _spawner.GlobalPosition; enemy._Init(path); _enemies.AddChild(enemy); }
public override void _Input(InputEvent @event) { if (@event is InputEventMouseButton) { if ((@event as InputEventMouseButton).ButtonIndex == 1 && (@event as InputEventMouseButton).Pressed) { Vector2[] path = navigation2D.GetSimplePath(player.Position, (@event as InputEventMouseButton).Position); line2D.Points = path; player.Path = new List <Vector2>(path); } } }
protected virtual void FindPath() { try { Vector2[] path = nav.GetSimplePath(this.Position, player.Position); currentPath = new List <Vector2>(path); } catch (Exception e) { GD.Print(e.Message); } }
private void GetPath() { if (!dead) { path = navigation2D.GetSimplePath(Position, player.Position, false); this.path = path; this.pathSize = 0; foreach (Vector2 item in path) { pathSize++; } currentPathPointIndex = 1; } }
/* INPUT MANAGEMENT */ public static void MapClick(Vector2 location, Navigation2D nav = null) { foreach (PlayerCharacter pc in _lcm.Selected) { pc.AttackTarget = null; if (nav != null) { pc.AddToPath(nav.GetSimplePath(pc.Position, location), Input.IsActionPressed("modify")); } else { pc.AddToPath(new Vector2[] { location }, Input.IsActionPressed("modify")); } } }
private void UpdatePath() { if (_navigation2D == null) { if (GameManager.Instance.SceneManager.CurrentLevel != null) { _navigation2D = GameManager.Instance.SceneManager.CurrentLevel.Navigation2D; } else { return; } } _path = _navigation2D.GetSimplePath(Position, GameManager.Instance.Player.Position).ToList(); }
public override void _UnhandledInput(InputEvent @event) { if (@event is InputEventMouseButton click && @event.IsPressed()) { if (click.ButtonIndex == (int)ButtonList.Right) { path = map.GetSimplePath(GlobalPosition, GetGlobalMousePosition(), true); path = path.Skip(1).ToArray(); // line.Points = path; // foreach (Vector2 item in path) // { // GD.Print(item); // } } } // state._StateUnhandledInput(@event); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { GD.Print("doing ready on " + this.Name); floor = GetNode("Navigation2D/TileMap") as TileMap; pathmaker = GetNode("Navigation2D") as Navigation2D; Vector2 startPoint = pathmaker.GetClosestPoint(new Vector2(25, 25)); Vector2 endPoint = pathmaker.GetClosestPoint(new Vector2(350, 25)); //var difDemoPath = pathmaker.GetSimplePath(startPoint,endPoint, true) as Godot.Collections.Array<Vector2>; Vector2[] demoPath = pathmaker.GetSimplePath(startPoint, endPoint, true); GD.Print(demoPath.ToString()); foreach (var point in demoPath) { GD.Print("raw points: " + point); GD.Print("tilepoints: " + floor.WorldToMap(point)); } base._Ready(); }
public void MoveToPosition(Vector2 destination) { _path = _navigation2D.GetSimplePath(GlobalPosition, destination).ToList(); }
/** * We used this to get the paths from a navigation2d and then tell it where we wanted it to go. * Nav2D path finding is a little wonky because it ignores objects and it's best that you do something like * custom points for added padding. I'm sure custom coding could make this much nicer */ public void old_SetPaths(Navigation2D nav, Vector2 dest) { var paths = nav.GetSimplePath(Position, dest, false); _paths = paths.Skip(1).Take(paths.Length - 1).ToArray(); }
private void GetPath(RequestPathEvent rpei) { //Get the generated path Vector2[] path = nav2D.GetSimplePath(rpei.requester.GlobalPosition, rpei.target.GlobalPosition); rpei.path = path; }
private void UpdateNavigationPath(Vector2 start, Vector2 end, int i) { _paths[i] = _navigation2D.GetSimplePath(start, end); _paths[i] = _paths[i].Skip(1).Take(_paths[i].Length - 1).ToArray(); }
public Vector2[] FindPath(Vector2 start, Vector2 end) { return(navmesh.GetSimplePath(start, end)); }
public override void _Ready() { //Viewport. wavePauseTimer = GetNode <Timer>("WavePauseTimer"); wave = LoadWave(waveCount - 1); //ASSIGN WORLD GRID worldGrid = FindNode("WorldGrid") as TileMap; //LOAD TOWER SCENE towerScenes.Add("Tower", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Tower.tscn")); towerCosts.Add("Tower", 40); towerScenes.Add("Shoot", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Shoot.tscn")); towerCosts.Add("Shoot", 40); towerScenes.Add("Mortar", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Mortar.tscn")); towerCosts.Add("Mortar", 50); towerScenes.Add("Shotgun", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Shotgun.tscn")); towerCosts.Add("Shotgun", 60); //LOAD ENEMY SCENE enemyScenes.Add("Enemy", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Enemy.tscn")); enemyScenes.Add("EnemyBig", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/EnemyBig.tscn")); enemyScenes.Add("Goblin", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Goblin.tscn")); enemyScenes.Add("Elephant", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Elephant.tscn")); enemyScenes.Add("Fast", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Fast.tscn")); enemyScenes.Add("Carriage", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Carriage.tscn")); //PATH FINDING debugLine = FindNode("DebugLine") as Line2D; debugLineSnapped = FindNode("DebugLineSnapped") as Line2D; nav2d = GetNode <Navigation2D>("Navigation2D"); spawn = GetNode <Node2D>("Spawn"); goal = GetNode <Node2D>("ParasitNiklas"); path = nav2d.GetSimplePath(spawn.GetGlobalPosition(), goal.GetGlobalPosition(), false); debugLine.Points = path; bDL = FindNode("bDL") as Line2D; //ALIGN PATH TO GRID GD.Print(path.Length); path = PathSnapToGrid(path); GD.Print(path.Length); debugLineSnapped.Points = path; money = GetTree().GetRoot().GetNode("World").FindNode("Money") as Label; GD.Print(money.GetName()); health = GetTree().GetRoot().GetNode("World").FindNode("Health") as Label; GD.Print(health.GetName()); EarnMoney(100); UpdateHealth(1000); Tuple <Vector2, int> tuple = BackTrackPath(path, worldGrid.MapToWorld(new Vector2(8, 6)), 24, 3); GD.Print("btpi: ", tuple.Item2); }
private void MakePath() { Vector2 nextDestination = _possibleDestinations[Global.GlobalRandom.Next() % _possibleDestinations.Count]; _path = _navigation2D.GetSimplePath(GlobalPosition, nextDestination, false).ToList(); }