Advertisement
Deozaan

Vertically Align Godot Camera2D

Jul 11th, 2021 (edited)
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://godotforums.org/discussion/25030/how-do-i-vertically-align-the-viewport-to-not-the-top-when-it-becomes-bigger-than-its-limits
  2. # https://archive.is/vFXJP
  3.  
  4. extends Camera2D
  5.  
  6.  
  7. # -1 = Top
  8. # >-1 and <-0.5 = Range between Top and Middle
  9. # -0.5 = Middle
  10. # >-0.5 and <0 = Range between Middle and Bottom
  11. # 0 (Or better remove the script) = Bottom
  12. export (float) var cam_extension_direction_y = -0.5
  13.  
  14.  
  15. onready var camera = get_node(".")
  16.  
  17.  
  18. func _process(_delta):
  19.         align_view()
  20.  
  21.  
  22. func align_view():
  23.     if get_viewport_rect().size.y > camera.limit_bottom:
  24.         camera.limit_top = ( get_viewport_rect().size.y- camera.limit_bottom ) * cam_extension_direction_y
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement