Hello folks,
I am a newcomer on Godot Engine (less than a week using Godot) and
and I'm learning how to better organize the project.
My game has a common behavior among objects that is follow another object and I don't want repeat the same code for each different object. So I created a new scene with a generic Node called FollowBehavior and attached a script. The script look like this:
# FollowBehavior.gd
extends Node
var object
var target
func init(_object, _target):
object = _object
target = _target
func _ready():
pass
func _process(delta):
# MY LOGIC HERE
I added FollowBehavior as a child node in some objects and in their respective scripts I did this:
# Object with follow behavior
func _ready():
$FollowBehavior.init(self, other_object)
Is there a better alternative for this? Is it the "best" way?