Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera2D zoom & smoothing problem #2074

Closed
FEDE0D opened this issue Jun 12, 2015 · 14 comments · May be fixed by #63773
Closed

Camera2D zoom & smoothing problem #2074

FEDE0D opened this issue Jun 12, 2015 · 14 comments · May be fixed by #63773

Comments

@FEDE0D
Copy link
Contributor

FEDE0D commented Jun 12, 2015

When the camera2D is moving and the zoom is updated, the camera movement makes a "stop" and then continues. Note this only occurs when using a smoothing factor other than 0.

I'm using dynamic changes in the camera properties using the Tween class and this is very noticeable. I don't know if this only applies to zoom only or other properties as well.

I include a test project: https://dl.dropboxusercontent.com/u/274954519/bugZoom2D.zip
Use LEFT-RIGHT to move and 1, 2, 3 to set the zoom.
Notice how the speed of the camera changes, even when setting the same zoom multiple times. Also, everything seems to work fine if the smoothing is 0

@guilhermefelipecgs
Copy link
Contributor

I don't think this is a bug, I changed your code a little and I think it's pretty good now. try it.

extends KinematicBody2D

var zoom = Vector2(1, 1)
var old_zoom

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    if Input.is_action_pressed("ui_left"):
        move(Vector2(-400 * delta, 0))
    if Input.is_action_pressed("ui_right"):
        move(Vector2(400 * delta, 0))

    old_zoom = zoom

    if Input.is_action_pressed("zoom_1"):
        zoom = Vector2(1, 1)
    if Input.is_action_pressed("zoom_2"):
        zoom = Vector2(1.5, 1.5)
    if Input.is_action_pressed("zoom_3"):
        zoom = Vector2(2, 2)

    if old_zoom != zoom:
        get_node("Camera2D").set_zoom(zoom)

@guilhermefelipecgs
Copy link
Contributor

Maybe this only hide the bug, I dunno, but the result is very better.

@FEDE0D
Copy link
Contributor Author

FEDE0D commented Sep 3, 2015

This only hides the bug.
That snippet code was just for showing the bug.
On my oroject I was using several Cameras and using Tween to change the values of the main cam to one of the others for a smothing transition. This bug hold me back from doing that.

@guilhermefelipecgs
Copy link
Contributor

Strange, I was thinking that this error is because the key press was calling the set_zoom often, but I tried this way and it's working fine.
original code with bug:

...
if Input.is_action_pressed("zoom_1"):
    get_node("Camera2D").set_zoom(Vector2(1, 1))
if Input.is_action_pressed("zoom_2"):
    get_node("Camera2D").set_zoom(Vector2(1.5, 1.5))
if Input.is_action_pressed("zoom_3"):
    get_node("Camera2D").set_zoom(Vector2(2, 2))

new code:

var zoom = Vector2(1,1)
...
func _fixed_process(delta):
    ...
    if Input.is_action_pressed("zoom_1"):
        zoom = Vector2(1, 1)
    if Input.is_action_pressed("zoom_2"):
        zoom = Vector2(1.5, 1.5)
    if Input.is_action_pressed("zoom_3"):
        zoom = Vector2(2, 2)

    get_node("Camera2D").set_zoom(zoom)

I don't understood what's happening.

@guilhermefelipecgs
Copy link
Contributor

I expected the camera stays with the bug.

@guilhermefelipecgs
Copy link
Contributor

Well, bug confirmed for me.

@FEDE0D
Copy link
Contributor Author

FEDE0D commented Sep 3, 2015

Yeap. I came to the same conclusion. It's on the update_scroll function.
I tried to fix it with no luck.

@guilhermefelipecgs
Copy link
Contributor

_update_scroll and smoothing is not synchronized.

@guilhermefelipecgs
Copy link
Contributor

I know if we remove _update_scroll or do this,

void Camera2D::set_zoom(const Vector2 &p_zoom) {

    zoom = p_zoom;
    Point2 old_smoothed_camera_pos = smoothed_camera_pos;
    _update_scroll();
    smoothed_camera_pos = old_smoothed_camera_pos;
};

it's works, but I dunno if I can do this.

@FEDE0D
Copy link
Contributor Author

FEDE0D commented Sep 3, 2015

You can try creating a Pull Request and see if they aprove it.
I did something similar with a bug in Parallax Background and I'm still waiting to be merged.

@guilhermefelipecgs
Copy link
Contributor

Do you tested this in your project?
If it's working I'll send a pr.

2015-09-03 18:57 GMT-03:00 Federico notifications@github.com:

You can try creating a Pull Request and see if they aprove it.
I did something similar with a bug in Parallax Background and I'm still
waiting to be merged.


Reply to this email directly or view it on GitHub
#2074 (comment).

guilhermefelipecgs added a commit to guilhermefelipecgs/godot that referenced this issue Sep 3, 2015
@FEDE0D
Copy link
Contributor Author

FEDE0D commented Nov 10, 2015

I can confirm this still happens on the 2.0 alpha build (20151030).

@akien-mga
Copy link
Member

Did you try the proposed patch da895e8 by @guilhermefelipecgs?

@akien-mga akien-mga changed the title [BUG] Camera2D zoom & smoothing problem Camera2D zoom & smoothing problem Nov 10, 2015
@FEDE0D
Copy link
Contributor Author

FEDE0D commented Nov 10, 2015

Yes. Its working right.
@guilhermefelipecgs Can you make a pull request for this file?

huhund pushed a commit to huhund/godot that referenced this issue Nov 10, 2020
…hing enabled

Fix godotengine#16323 in 3.2 branch. Apply same solution of godotengine#2074 in rotation and offset.
edg1000 pushed a commit to edg1000/https-github.com-godotengine-godot that referenced this issue Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants