Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | AUD_FOR_IUV |
Hello everyone! I’m having some trouble trying to implement a celeste-style room transition in this small platformer game that I’m working on. My strategy has been to use a Tween on the camera to interpolate the camera limits to the new room’s dimensions when the player enters a new room. This works really well when the entire room fits within the viewport, as shown here, but when the room is larger than the viewport the interpolation seems to introduce this weird jittery effect, as shown here. The code that is run every time the player enters a room is roughly as follows:
extends Camera2D
func transition(room: Room) -> void:
$Tween.stop_all()
var room_dimensions := _get_room_dimensions(room)
_interpolate_property('limit_left', self.limit_left, room.global_position.x)
_interpolate_property('limit_right', self.limit_right, room.global_position.x + room_dimensions.x)
_interpolate_property('limit_top', self.limit_top, room.global_position.y)
_interpolate_property('limit_bottom', self.limit_bottom, room.global_position.y + room_dimensions.y)
$Tween.start()
func _interpolate_property(prop, start, end) -> void:
var duration := 0.25
var trans := Tween.TRANS_LINEAR
var easing := Tween.EASE_OUT
$Tween.interpolate_property(self, prop, start, end, duration, trans, easing)
func _get_room_dimensions(room: Room) -> Vector2:
var half_extents = room.get_node('Area2D').get_node('CollisionShape2D').shape.extents
return 2 * half_extents
Here, every room is assumed to have an Area2D that defines its boundaries, and the origin is always in the upper left corner of the room. My experimentation seems to suggest that rooms that are either wider or taller than the viewport will introduce this jittering (the room I enter in the second link is a long hallway that continues to the right past the viewport).
Any idea on what might be happening? Thanks in advance for the help!