Having issues with Marker2D

Godot Version

4

Question

I need help with my code, I’m very new to coding and I’m having issues with my Marker2D and Global position code on line 25. Whenever I play the debug and I hit the enter key it crashes and I get an error "Invaild set index ‘position’ (on base: ‘Node’) with value of type ‘Vector2’ ". I have no idea what this means and I’m trying to figure it out Heeeeeelp! (I was following this tutorial and got stuck around 4:00 - 4:30 https://www.youtube.com/watch?v=2G41KECXXn4&t=421s)

extends CharacterBody2D

const bulletpath = preload('res://Bullet.tscn')







func _ready():
	pass
	
	

func _process(_delta):
	if Input.is_action_just_pressed("ui_accept"):
		print("pew pew!")
		shoot()
	
	#bullet function needs to be looked at for shooting a bullet - Godot Tutorial go to timestamp: 3:52
func shoot():
	var bullet = bulletpath.instantiate()
	get_parent().add_child(bullet)
	bullet.position = $Marker2D.global_position

Look like the root node of your bullet packed scene it’s a node and not a node2d. Your try to define the position as a vector2 but node accept a vector3 as position.

1 Like

I think you must have defined Bullet as Node.
The Node node doesn’t have a position property.
You may have to change that to Node2D.

1 Like

thank you so much for the help, it works now!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.