Im trying to get an altimeter

Godot Version

4.3

Question

im trying to get myself an altimeter on my game.
`extends Label

var altimeter = self.global_position.y

func _process(delta: float) → void:
text = “Altitude: %s” %altimeter

func _on_launch_pressed() → void:
self.visible = true
`
but it only gives the coordinates on my players scene and not the maps. Is there a way of fixing this?
1234
Rocket is the player

Making a basic type variable will copy the value, so self.global_position.y is copied once into altimeter, what ever the starting position is will be saved and never updated.

I’d recommend instead getting a variable to a reference of Rocket maybe by get_parent() then use the position of that

extends Label

@onready var rocket: Node2D = get_parent()

func _process(delta: float) -> void:
    text = "Altitude: %s" % rocket.global_position.y
2 Likes

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