camera.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. extends Spatial
  2. # Declare member variables here. Examples:
  3. # var a = 2
  4. # var b = "text"
  5. var x_sensitivity = 0
  6. var y_sensitivity = 0
  7. var is_drag = false
  8. var helper
  9. var camera
  10. var zoom
  11. var planet
  12. func _input(event):
  13. if event is InputEventMouseButton:
  14. if event.button_index == BUTTON_RIGHT:
  15. is_drag = event.pressed
  16. if event.button_index == BUTTON_WHEEL_UP and zoom > 0.1:
  17. zoom -= .1
  18. camera.translation = Vector3(0,0,zoom*zoom*zoom*zoom+1.1)
  19. if event.button_index == BUTTON_WHEEL_DOWN:
  20. zoom += .1
  21. #print(zoom)
  22. camera.translation = Vector3(0,0,zoom*zoom*zoom*zoom+1.1)
  23. if event is InputEventMouseMotion and is_drag:
  24. self.rotate_y(event.relative.x/x_sensitivity)
  25. helper.rotate_x(event.relative.y/y_sensitivity)
  26. # Called when the node enters the scene tree for the first time.
  27. func _ready():
  28. x_sensitivity = -200
  29. y_sensitivity = -200
  30. helper = get_node("helper")
  31. camera = get_node("helper/camera")
  32. camera.translation = Vector3(0,0,2)
  33. zoom = 2
  34. planet = 1
  35. pass # Replace with function body.