Godot Version
Godot v4.1.1.stable
Question
So basically I want a jack-in-the-box type of attack mechanic where something springs out of the enemy and stays there for a while (relative to the enemy) before moving back to the enemy’s position. However my enemy is moving along the y axis as it shoots so the “Jack-in-the-box” does not follow the enemy in terms of y axis position. Sorry if this is a dumb question because I have almost 0 experience.
Here is my bullet (“Boxing Glove”) code:
extends Area2D
var speed = 5000
var direction = Vector2(-1, 0)
Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta):
position += speed * direction * delta
speed -= 45
And here is the attack code:
func attack3():
var boxing_glove = boxing_glove_node.instantiate()
get_tree().current_scene.call_deferred(“add_child”, boxing_glove)
boxing_glove.position = global_position