Hi
I have a game with a player and a bunch of so called "Gravity Objects" that have some effects when the player enters them. Here is the tree for a gravity object (scene):
Here is what a gravity object looks like. The green rectangle on the bottom is the indicator, for which the y-position should be the same as the player's y-position:
BottomIndicator is a sprite that is supposed to indicate how close the player is to the center of the gravity object. There will also be one for the top, right and left, forming a rectangle all together. For simple testing purposes, the bottom indicator should just have the same global y-position as the player. When I add the top and left indicators (sprites), their position should be relative to the player's x-position. I have been experimenting with to_local()
and to_global()
on the player's and the indicator's position, but only the y-position seems to be the same. Even though they appear to be the same, when I set the indicator sprite's y-position equal to the player's y-position, the indicator seems to disappear. I assume that it's been moved way off the viewport because I'm adding a lot to it's local position.
I have this code in the _process() of my GravityObject:
$BottomIndicator.position.y = player.position.y
print("Player pos: ", player.position)
print("Player local: ", to_local(player.position))
print("Player global: ", to_global(player.position))
print("Indicator pos: ", $BottomIndicator.position)
print("Indicator local: ", to_local($BottomIndicator.position))
print("Indicator global: ", to_global($BottomIndicator.position))
print()
output:
Player pos: (410.162476, 4177.202148)
Player local: (19.824463, -46.077637)
Player global: (800.500488, 8400.482422)
Indicator pos: (0.707123, 4177.202148)
Indicator local: (-389.63089, -46.077637)
Indicator global: (391.045135, 8400.482422)
What is a good way to solve this problem? Can I set the global position of BottomIndicator from within the GravityObject script? I'm feeling lost. Thanks in advance