Camera limits dont update🎥

Godot Version

4.4.1 stable

Question

i made a system that detects if you enter a room and sets the camera limits to the new room’s collision shape, but if you switch fast from rooms there is a chance that the limits dont update(btw i have position smoothing on and limit smoothing on for smooth transition)

func _on_room_handler_area_entered(area: Area2D) -> void:
	if area.name != "Box":
		transition = true
		call_deferred("room_transition", area)

func room_transition(area: Area2D) -> void:
	var cam: Camera2D = $"../Camera2D"
	

	var collision_shape: CollisionShape2D = area.get_node("CollisionShape2D")
	var size = collision_shape.shape.extents * 2
	var view_size = get_viewport_rect().size
	
	if size.y < view_size.y:
		size.y = view_size.y
	if size.x < view_size.x:
		size.x = view_size.x

	cam.limit_top = collision_shape.global_position.y - size.y/2
	cam.limit_left = collision_shape.global_position.x - size.x/2
	cam.limit_bottom = cam.limit_top + size.y
	cam.limit_right = cam.limit_left + size.x

	
	transition = false

Do you have a reason for using call_deferred?

If not, I would try calling room_transition without it and see if that fixes the issue.

1 Like

it was a way to fix the issue but did nothing and after deleting the line the same problem was still there, its a weird bug

I suspect the issue is one of timing - specifically that something doesn’t get updated fast enough when you switch a room quickly.

Which raises an interesting question - what do you mean by switching fast from a room?

so rooms are area2D nodes with a collissionshape2D, when you enter a room the code will calculate the size of hte collissionshape and make update the camera limits to the collissionshape borders and i turned limit_smoothing on

so the transitions goes smooth and not switch instantly, so at the end of a room the camera stops moving. if you exit and enter a room really fast, the camera limits wont update and the camera will be at the previous room while you are in another room. but without limit_smoothing, there is no bug, so how can i fix it while having limit_smoothing on :slight_smile:

Not an ideal solution - but have you tried inserting a small sleep statement?

no, i didn’t try it yet

Try adding reset_smoothing() before you apply a new limit.

1 Like

didnt work either :frowning: i get of the new room while the transition is happenning, i think the camera limits do not update while transitioning, thats why on instant transitions there are no bugs, but how can i make the update happen even while the transition?

You could insert another transition between your transitions. In the game I am working on a black screen is shown when the player goes from one area to another. Basically I drop the curtain while I am changing the stage then raise it again when the scene finishes loading.

You could also remove the ability to switch rooms quickly. If you disable the transition point for a few seconds after a player enters the room you eliminate their ability to see this issue.

yeah, i can do that but its not ideal for platformer games like im trying to make

You could also remove the ability to switch rooms quickly. If you disable the transition point for a few seconds after a player enters the room you eliminate their ability to see this issue.

thanks for the idea but its a platformer, the player must move a lot

Usually the best thing to do in these circumstances is debug print everything relevant, and see if you’re getting the values you expect.

You may well find you have overlapping transitions or stale values.

i did that and i realized that when you are in 2 collisionshapes, there is a chance for the camera to not update