This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

First, I'm a beginner in Godot and Game dev.

My Q: In Godot I'm using a Light2D following the player (acting as a kind of main light). The root of the scene "player" is a KinematicBody2d and the Light2D and Camera2d are child nodes. For the camera smoothing is enabled. As explained within the Godot documentation, I can use getcamerascreen_center() to get the real position of the camera. I thought something as simple as
light.position = $"Camera".get_camera_position()
would position the texture of the Light2D right. But now, the top/left corner of the light texture is somewhere in the bottom/right corner of the screen. What do I miss? How to calculate the offset to use? ( I tried half of the view port size but this is still incorrect.)

I would most like to have a signal emitted from the Light2D (with the real position) every time the real (smoothed) position is changing. But this seems not to be not implemented.

Godot version 3.3.2
in Engine by (25 points)

1 Answer

0 votes
Best answer

I needed to set the global position of the light because the position is relative to the parent node.

$Light2D.global_position = $Camera2D.get_camera_screen_center()

by (25 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.