ScottyWired

I don't know who's reading this but have fun

Aug 7th, 2021 (edited)
1,569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Area2D
  2.  
  3. var mouse_radians
  4. var sprite_sheet_hframes
  5. # Called when the node enters the scene tree for the first time.
  6. func _ready():
  7.     sprite_sheet_hframes = $Sprite.hframes
  8.     pass # Replace with function body.
  9.  
  10. # Called every frame. 'delta' is the elapsed time since the previous frame.
  11. func _process(delta):
  12.     get_mouse_radians()
  13.     set_sprite()
  14.     pass
  15.  
  16. func get_mouse_radians():
  17.     mouse_radians = get_angle_to(get_global_mouse_position())
  18.     if mouse_radians < 0:
  19.         mouse_radians += PI + PI
  20.     pass
  21.  
  22. func set_sprite():
  23.     sprite_sheet_hframes = $Sprite.hframes
  24.     var target_sprite = Maths.scale(mouse_radians, 0, 2*PI, 0, sprite_sheet_hframes)
  25.     $Sprite.frame = int(target_sprite)
  26.  
Add Comment
Please, Sign In to add comment