Can't get the position of a maker2d

Godot Version 4.2.1

I’m trying to get the global position of a marker 2d and have that sent in a signal called grenade ,however when I do that I get a stack trace saying invalid get index ‘global_position’ (on base ‘marker2d’)
Code:
if Input.is_action_just_pressed(“Secondary”) and can_grenade:
var grenade_pos = $LaserStart.get_children()[0].global_positon
Grenade.emit(grenade_pos)
can_grenade=false
$GrenadeCooldown.start()
any help?
and why is it that i have the exact same code for my other scene and yet it works perfectly?
note the only difference i know is that this scene has a rigidbody2d as the main node while the one that works has an area 2d
edit: reconnecting my signal seems to have solved the issue?
thank you everyone for your replies

I don’t know why it can’t works.
But there’s another way to get global position:
Use Node2D.to_global(Vector2) to convert local_position to global position.
Changed code:

if Input.is_action_just_pressed(“Secondary”) and can_grenade:
    var grenade_pos = to_global($LaserStart.get_children()[0].position)
    Grenade.emit(grenade_pos)
    can_grenade=false
    $GrenadeCooldown.start()
1 Like

change to this:
var grenade_pos = $LaserStart.get_child(0).global_positon

1 Like

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