camera.gd 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 planet
  9. var helper
  10. var camera
  11. var zoom
  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/target")
  32. zoom = 2
  33. camera.translation = Vector3(0,0,zoom*zoom*zoom*zoom+1.1)
  34. pass # Replace with function body.