Advertisement
LukeMaster06

r/godot - 2D FNAF-Style Panning (Godot 4)

May 23rd, 2023
2,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # not from an actual project (I deleted it recently, oops), this is just a sample of what I did to achieve camera panning (really bad
  2. # code, and I don't even know if it works)
  3.  
  4. extends Node2D
  5.  
  6. @onready var pov = $Camera2D
  7. var moving_left = false
  8. var moving_right = false
  9. var pan_speed = 5
  10.  
  11.  
  12. func _process(_delta: float) -> void:
  13.     if moving_left:
  14.         pov.position.x -= pan_speed
  15.     elif moving_right:
  16.         pov.position.x += pan_speed
  17.  
  18.  
  19. func _on_left_mouse_entered():
  20.     moving_left = true
  21.  
  22.  
  23. func _on_left_mouse_exited():
  24.     moving_left = false
  25.  
  26.  
  27. func _on_right_mouse_entered():
  28.     moving_right = true
  29.  
  30.  
  31. func _on_right_mouse_exited():
  32.     moving_right = false
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement