Advertisement
julong

Untitled

Apr 13th, 2022
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. extends Spatial
  2.  
  3. var enabled = false
  4.  
  5. export var x_offset = 0
  6. export var y_offset = 0
  7. export var z_offset = 0
  8.  
  9. export var inverse_x = false
  10. export var inverse_y = false
  11.  
  12. export var sensitivity_x = 300
  13. export var sensitivity_y = 300
  14.  
  15. export (NodePath) var target
  16. onready var sprite = get_node(target)
  17.  
  18. # Called when the node enters the scene tree for the first time.
  19. func _ready():
  20.     Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
  21.     enabled = true
  22.     inverse()
  23.    
  24. # Called every frame. 'delta' is the elapsed time since the previous frame.
  25. func _process(_delta):
  26.     transform.origin.y = sprite.transform.origin.y + y_offset
  27.     transform.origin.z = sprite.transform.origin.z + z_offset
  28.     transform.origin.x = sprite.transform.origin.x + x_offset
  29.    
  30. func inverse():
  31.     if inverse_x:
  32.         sensitivity_x *= -1
  33.     if inverse_y:
  34.         sensitivity_y *= -1
  35.  
  36. # Call this methods once for toggle axis inversion.
  37. func _inverse_x():
  38.     sensitivity_x *= -1
  39.    
  40. func _inverse_y():
  41.     sensitivity_y *= -1
  42.  
  43. func _input(event):
  44.     if Input.is_action_pressed("ui_cancel"):
  45.         Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
  46.         enabled = false
  47.     if event is InputEventMouseMotion && enabled:
  48.         rotation.y += event.relative.x / -sensitivity_x
  49.         rotation.x += event.relative.y / -sensitivity_y
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement