Sprite2D just dissapearing, event though another Sprite2D has the same code and works fine

Godot Version

Godot 4.6

Question

So I’m trying to make two Sprite2Ds(which in here are called “CameraA” and “CameraB”) move in a specific manner. Their parent nodes need to track the position of the player relative to themselves, and place the Sprites opposite of the player. Both sprites are moved in the same way, but one of them just disappears

Here’s the code:

extends Node2D


# get the portals
@onready var PortalA: Sprite2D = $"Portal A"
@onready var PortalB: Sprite2D = $"Portal B"

# get the cameras
@onready var CameraA: Sprite2D = $"Portal A/Camera A"
@onready var CameraB: Sprite2D = $"Portal B/Camera B"

# variables for player's position relative to portals
var playerPosA: Vector2
var playerPosB: Vector2

# get the player
var player: CharacterBody2D 
func _ready() -> void:
	player = get_node("player")

func _process(_delta: float) -> void:
	# make portals track the players position relative to them
	playerPosA = player.global_position - PortalA.global_position
	playerPosB = player.global_position - PortalB.global_position
	
	# apply the relative position of the player to cameras
	CameraA.position = -playerPosB
	CameraB.position = -playerPosA

The issue seems to be because I made the “playerPosB” negative, because when it’s normal the “CameraA” doesn’t disappear. I specifically need both of them to be negative.

Here is the node tree:

you can check the position of camera A and camera B in “Remote” when running your game, it might help with debugging

2 Likes

Thank you for reminding, I completely forgot about this!

Turns out Camera A was behind Camera B, so I just couldn’t see it

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