enemies appearing at certain point

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By VanBandama
:warning: Old Version Published before Godot 3 was released.

Hi!
I’m working on little cave-like shmup. I already made all the assets. Now I’m trying to achive appearance of some enemies. I want them to be shown behind player ship at certain point in a game. Unfortunately when I place them off-side the main game screen, it doesn’t work. Previously I worked on Game Maker studio and there was option to draw path for sprites to follow. Can anyone tell me what to do?

:bust_in_silhouette: Reply From: raymoo

You can make a path for nodes to follow using Path2D and PathFollow2D as follows:

  1. Create a Path2D in the editor and select it in the node tree. Tools for editing the path should appear above the 2D preview.
  2. Use the tools to create a curve. If you hover your mouse cursor over a button it will show a tooltip describing the tool.
  3. Create a PathFollow2D as a child of the Path2D. It doesn’t matter if you do this in the editor or programatically at runtime.
  • If a PathFollow2D is the child of a Path2D, it can be moved along the path using its method set_offset(float). Every child of PathFollow2D will be moved along with it.
  1. Advance the PathFollow2D somehow at runtime. I did this in my test project by giving it the following script:
extends PathFollow2D

export var SPEED = 100

func _ready():
	set_fixed_process(true)

func _fixed_process(delta):
	set_offset(get_offset() + SPEED * delta)
  1. Put stuff you want to move along the path as children of the PathFollow2D.

Example project (Run the Path2D.tscn scene): nya.is