June 2018
Beginner to intermediate
298 pages
7h 38m
English
Attach a script to the Enemy scene. To begin, you'll make the code that will select a path and move the enemy along it:
extends Area2Dsignal shootexport (PackedScene) var Bulletexport (int) var speed = 150export (int) var health = 3var followvar target = nullfunc _ready(): $Sprite.frame = randi() % 3 var path = $EnemyPaths.get_children()[randi() % $EnemyPaths.get_child_count()] follow = PathFollow2D.new() path.add_child(follow) follow.loop = false
A PathFollow2D node is one that can automatically move along a parent Path2D. By default, it is set to loop around the path, so you need to manually set the property to false.
The next step is to move along the path:
func _process(delta): follow.offset += speed * delta position ...
Read now
Unlock full access