+1 vote

I am using a Camera2D attached to the root node, even though the camera ultimately moves with the player through code. The reason for this is to have more flexibility.

I have been using Camera2D.set_offset() for that purpose and no problems so far.
But in the docs is written about set_offset(): "Set the scroll offset. Useful for looking around or camera shake animations."
Which makes me think if it is a good idea to use every frame.

So, is it ok?
If not, what other ways there are?

in Engine by (388 points)

1 Answer

+3 votes
Best answer

set_offset() is another way to move the camera relatively from its position, without actually modifying the transform of the Camera node. It should be allright to call it on every frame.

It is intented to be used as a secondary positionning parameter. Screen shake is given as an example because it typically doesn't changes the camera's looking target, but has to make it move a bit around it. You could do everything with set_pos(), but using set_offset() can make logic work independently from the transform.

I think this is also useful if you enabled smoothing, because set_offset() won't be affected by it, unlike set_pos() (didn't tested yet, thought).

by (29,120 points)
selected by

Thanks!
You are correct, set_offset() ignores smoothing.
set_pos() causes some weird screen shakes occasionally. As I will be developping I will try to check if it is my code or a Godot issue.

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.