Godot Version
Godot 4
Question
Hi! So, I have 2 global variables that each track the position of a different sprite in their respective scene and then set the other sprite to that position when switching, then I have a button to switch between scenes, so when I switch to SCENE 2 for example, the sprite will be in the same position as SCENE 1’s and vice versa
BUT
every time I switch to SCENE 2, the position.x is right, but the position.y is not.
What’s wrong?
func _ready() -> void:
position = Global.vr_dude_position
Global.vr_dude_position is a Global var that is set to vr_dude’s position in its scene
BTW i cannot do the opposite as vr dude is the first to load i cannot then go back to him after going to real_dude(the other sprite) as Global.real_dude_position (literally the same thing as before but for vr_dude) is considered of type Nil, what could i do about it?
When you say height… are you talking about scale property?
1 Like
Ops, I forgot to explain myself, I was in a hurry.
Basically I meant the position (position.y I think, as is the height in the scene different) in the scene.
The two vieports are structured identically but in one there’s some tiles from a tileset that make pillars and I can make the character jump on them, if I switch to the scene that doesn’t have them, two things may happen:
If it’s a low pillar then when the scene without the pillars is loaded the character will appear already on the ground.
On High Pillars when the scene switches it will be in air (and fall) but it will start falling from a lower position (height-wise, so position.y(?)) respect to where it should start in air.
All positions are relative to the origin of the scene (0,0). So if you’re trying to transpose coordinates from a sprite in one scene to a sprite in another you’ll need to be mindful of this.
For example, if you’re trying to “copy” a player location such that it’s 50 pixels from a door in one scene, if the door in both scenes are not at the same location, you’re going not going to get the result you want.
Depending on how your levels are set up and the results you’re trying to achieve, you may need to add additional logic to get what you want.
Am I correct in guessing that the two rooms you’re using in this example are not identical in layout and size?
1 Like
I don’t think that’s the problem…
My two rooms are literally Identical, they’re the same size, the size of the viewport.
And in my research I was able to notic that the position of sprite1 (for example, 149, 365) is different in respect to the viewport in scene 2.
I tried to set the same position to sprite2 in the inspector and somehow it was under the viewport.
I really don’t know how to solve.
I’m sorry, I must not be understanding the problem you’re describing. Could you try explaining it again? Screenshots would be very helpful. It doesn’t sound like it should be tough to diagnose if I’m able to follow along with the issue.