Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Diet Estus |
I have a Player which is aKinematicBody2D
with a Camera2D
. The camera has smoothing_enabled
and is set up to smoothly scroll until the player is in the center of the screen.
When my player lands on horizontally moving platforms, I make him a child of the platforms so that he moves along with them.
Here is the code for that re-parenting:
# if player is on moving platform, reparent him to that platform
if current_platform != null:
if not on_moving_platform:
if current_platform.name == "MovingPlatform":
var current_global_position = global_position
var new_parent = Game.get_node("Level/MovingPlatform")
get_parent().remove_child(self)
new_parent.add_child(self)
global_position = current_global_position
on_moving_platform = true
else:
...
Unfortunately, whenever my player lands on such a platform, the Camera2D
discretely cuts so that the player is centered in the screen. This is very ugly.
It seems that when you re-parent a node with a Camera2D
, the Camera2D
resets, ignoring its current scrolling position.
How can I avoid this so that landing on such platforms and re-parenting my Player does not cause discrete camera jumps?