-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e24efb3
commit 11c136a
Showing
6 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
extends NavigationPolygonInstance | ||
|
||
|
||
# Declare member variables here. Examples: | ||
# var a = 2 | ||
# var b = "text" | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
var p = NavigationPolygon.new() | ||
p.add_outline($Polygon2D.polygon) | ||
p.make_polygons_from_outlines() | ||
|
||
navpoly = p | ||
|
||
|
||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extends KinematicBody2D | ||
|
||
|
||
var target : Vector2 | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
$NavigationAgent2D.set_target_location(global_position) | ||
|
||
|
||
#func _physics_process(delta): | ||
|
||
func _input(event): | ||
if Input.is_mouse_button_pressed(BUTTON_RIGHT): | ||
print("new path") | ||
target = get_global_mouse_position() | ||
$NavigationAgent2D.set_target_location(target) | ||
print($NavigationAgent2D.get_nav_path()) | ||
$Line2D.points = $NavigationAgent2D.get_nav_path() | ||
|
||
|
||
func _physics_process(delta): | ||
if target: | ||
var next_position =$NavigationAgent2D.get_next_location() | ||
#print(next_position,global_position) | ||
var v = global_position.direction_to(next_position) * 20 | ||
$NavigationAgent2D.set_velocity(v) | ||
|
||
func _on_NavigationAgent2D_velocity_computed(safe_velocity): | ||
move_and_slide(safe_velocity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extends Node | ||
|
||
export(float) var velocity := 1.0 | ||
|
||
export (NodePath) var entity_path | ||
onready var entity = get_node(entity_path) as KinematicBody2D | ||
|
||
enum Direction {NO_MOVE, UP,DOWN,LEFT,RIGHT} | ||
|
||
func move(direction): | ||
var v = Vector2.ZERO | ||
match direction: | ||
Direction.UP: | ||
v = Vector2.UP | ||
Direction.DOWN: | ||
v = Vector2.DOWN | ||
Direction.LEFT: | ||
v = Vector2.LEFT | ||
Direction.RIGHT: | ||
v = Vector2.RIGHT | ||
_ : | ||
pass | ||
|
||
entity.move_and_slide(velocity*v) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters