-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'Navigation Polygon 2D' ported to Godot 4.1.1
- Loading branch information
Showing
10 changed files
with
87 additions
and
104 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,36 @@ | ||
extends CharacterBody2D | ||
|
||
|
||
var movement_speed: float = 200.0 | ||
@onready var navigation_agent: NavigationAgent2D = $NavigationAgent2D | ||
|
||
|
||
func _ready(): | ||
# These values need to be adjusted for the actor's speed | ||
# and the navigation layout. | ||
navigation_agent.path_desired_distance = 2.0 | ||
navigation_agent.target_desired_distance = 2.0 | ||
navigation_agent.debug_enabled = true | ||
|
||
|
||
# The "click" event is a custom input action defined in | ||
# Project > Project Settings > Input Map tab. | ||
func _unhandled_input(event): | ||
if not event.is_action_pressed("click"): | ||
return | ||
set_movement_target(get_global_mouse_position()) | ||
|
||
|
||
func set_movement_target(movement_target: Vector2): | ||
navigation_agent.target_position = movement_target | ||
|
||
|
||
func _physics_process(_delta): | ||
if navigation_agent.is_navigation_finished(): | ||
return | ||
|
||
var current_agent_position: Vector2 = global_position | ||
var next_path_position: Vector2 = navigation_agent.get_next_path_position() | ||
|
||
velocity = current_agent_position.direction_to(next_path_position) * movement_speed | ||
move_and_slide() |
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 @@ | ||
[gd_scene load_steps=4 format=3 uid="uid://ct7veakwiei3h"] | ||
|
||
[ext_resource type="Script" path="res://character.gd" id="1_8uimh"] | ||
[ext_resource type="Texture2D" uid="uid://b0wokaenwu7pj" path="res://character.png" id="1_rmg12"] | ||
|
||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_20ukx"] | ||
radius = 7.0 | ||
height = 22.0 | ||
|
||
[node name="Character" type="CharacterBody2D"] | ||
script = ExtResource("1_8uimh") | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="."] | ||
position = Vector2(0, -3) | ||
scale = Vector2(0.3, 0.3) | ||
texture = ExtResource("1_rmg12") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2(0, -3) | ||
shape = SubResource("CapsuleShape2D_20ukx") | ||
|
||
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."] |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
[gd_scene load_steps=4 format=3 uid="uid://bjgad00c2xiuc"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://bk26gi6qsuh18" path="res://map.png" id="2_nxfkp"] | ||
[ext_resource type="NavigationPolygon" uid="uid://bk5r48dcijlqt" path="res://navigation_polygon.res" id="3_6c0vu"] | ||
[ext_resource type="PackedScene" uid="uid://ct7veakwiei3h" path="res://character.tscn" id="4_n6iop"] | ||
|
||
[node name="Navigation" type="Node2D"] | ||
|
||
[node name="Map" type="Sprite2D" parent="."] | ||
z_index = -1 | ||
position = Vector2(400, 302) | ||
texture = ExtResource("2_nxfkp") | ||
|
||
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."] | ||
navigation_polygon = ExtResource("3_6c0vu") | ||
|
||
[node name="Character" parent="." instance=ExtResource("4_n6iop")] | ||
position = Vector2(211, 141) |
Binary file not shown.
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