Using a Marker 2D

Im trying to alter the point of origin of my bullet because I think it is what is making my project crash every time I shot a bullet,
I’ve heard that a Marker 2D can be used for this, but I’m not sure how with my current code:

func _physics_process(delta):
player_movement(delta)

#var supershootInput = Input.is_action_pressed("atirar")   



var shootInput = Input.is_action_just_pressed("atirar")
if shootInput:
	var newshoot = bolinha.instantiate()
	get_tree().root.add_child(newshoot)
	newshoot.global_position = global_position
	newshoot.dir = lastdir

If you want newshoot.gpos = marker.gpos, then try this:

newshoot.global_position = get_node("marker2d").global_position #marker's gpos

Does it works now?

2 Likes

I would personally set up a ref variable for the marker rather than using get_node all the time as its pretty slow.

3 Likes