I need to reference a Characterbody2d (Body) in a script in a other Characterbody2d (fist).
I am trying to reference Body in fist’s script so that I can aquire its position for the fist to use for its target I want it to constantly follow.
Don’t set initialize variables to things that won’t be ready instantly.
You could prepend @onready to some variables, but in this case it would be best to use the _ready function
@export var body: CharacterBody2D
var target: Vector2
func _ready() -> void:
target = body.position + Vector2(90, 45)
But then you’ll find that Vector2 is a copied value, not referenced, so it does not update after being set. You want to use body.position directly, as body is referenced.