Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/enemy/enemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extends CharacterBody2D

const SPEED = 100

@onready var player: CharacterBody2D = get_parent().get_node("Player")
@onready var navigator: NavigationAgent2D = $NavigationAgent2D


func _ready():
find_path()


func _physics_process(delta):
var direction = to_local(navigator.get_next_path_position()).normalized()
velocity = direction * SPEED
move_and_slide()


func find_path():
navigator.target_position = player.position


func _on_navigation_timer_timeout():
find_path()
17 changes: 14 additions & 3 deletions src/enemy/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
[gd_scene load_steps=3 format=3 uid="uid://d1t70mghq4jqo"]
[gd_scene load_steps=4 format=3 uid="uid://d1t70mghq4jqo"]

[ext_resource type="Texture2D" uid="uid://b6iglbqclfol6" path="res://icon.svg" id="1_1qbt2"]
[ext_resource type="Script" path="res://enemy/enemy.gd" id="1_axdwg"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_qol47"]
[sub_resource type="CircleShape2D" id="CircleShape2D_gftau"]

[node name="Enemy" type="CharacterBody2D"]
collision_layer = 4
collision_mask = 3
motion_mode = 1
wall_min_slide_angle = 0.0
script = ExtResource("1_axdwg")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_qol47")
shape = SubResource("CircleShape2D_gftau")

[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.15625, 0.15625)
texture = ExtResource("1_1qbt2")

[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
debug_enabled = true

[node name="NavigationTimer" type="Timer" parent="."]
wait_time = 0.1
autostart = true

[connection signal="timeout" from="NavigationTimer" to="." method="_on_navigation_timer_timeout"]
9 changes: 8 additions & 1 deletion src/map/map.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[gd_scene load_steps=8 format=3 uid="uid://y4brqgeqv22u"]
[gd_scene load_steps=9 format=3 uid="uid://y4brqgeqv22u"]

[ext_resource type="Texture2D" uid="uid://0p8c7ft70lv5" path="res://assets/SproutLands/Tilesets/Grass.png" id="1_53lk6"]
[ext_resource type="Texture2D" uid="uid://c5c0gkp3n78xa" path="res://assets/SproutLands/Tilesets/Hills.png" id="2_c7h1q"]
[ext_resource type="Texture2D" uid="uid://b8pa0fb7oeqby" path="res://assets/SproutLands/Objects/Basic_Grass_Biom_things.png" id="3_cdhlv"]

[sub_resource type="NavigationPolygon" id="NavigationPolygon_wpv7e"]
vertices = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])

[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_8q6ug"]
texture = ExtResource("1_53lk6")
0:0/0 = 0
Expand Down Expand Up @@ -174,6 +179,7 @@ texture = ExtResource("1_53lk6")
3:5/0 = 0
3:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
3:5/0/physics_layer_0/angular_velocity = 0.0
3:5/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_wpv7e")
4:5/0 = 0
4:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
4:5/0/physics_layer_0/angular_velocity = 0.0
Expand Down Expand Up @@ -610,6 +616,7 @@ texture = ExtResource("3_cdhlv")
[sub_resource type="TileSet" id="TileSet_fggcw"]
physics_layer_0/collision_layer = 2
physics_layer_0/collision_mask = 0
navigation_layer_0/layers = 1
sources/0 = SubResource("TileSetAtlasSource_8q6ug")
sources/1 = SubResource("TileSetAtlasSource_ucsp2")
sources/2 = SubResource("TileSetAtlasSource_0iofd")
Expand Down