Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This function should be called whenever the character moves.
- func update_camera(character_pos):
- var new_camera_pos = self.get_global_pos()
- # Check if the character reaches the right margin.
- if character_pos.x > self.get_global_pos().x + screen_size.width * (drag_margin_right - 0.5):
- new_camera_pos.x = character_pos.x - screen_size.width * (drag_margin_right - 0.5)
- # Check if the character reaches the left margin.
- elif character_pos.x < self.get_global_pos().x + screen_size.width * (drag_margin_left - 0.5):
- # Character reaches the left drag margin.
- new_camera_pos.x = character_pos.x + screen_size.width * (0.5 - drag_margin_left)
- # Clamp the new camera position within the limits.
- new_camera_pos.x = clamp(new_camera_pos.x, left_limit + screen_size.width * 0.5, right_limit - screen_size.width * 0.5)
- new_camera_pos.y = clamp(new_camera_pos.y, top_limit + screen_size.height * 0.5, bottom_limit - screen_size.height * 0.5)
- # Actually update the position of the camera.
- self.set_global_pos(new_camera_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement