Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Area2D
- var mouse_radians
- var sprite_sheet_hframes
- # Called when the node enters the scene tree for the first time.
- func _ready():
- sprite_sheet_hframes = $Sprite.hframes
- pass # Replace with function body.
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(delta):
- get_mouse_radians()
- set_sprite()
- pass
- func get_mouse_radians():
- mouse_radians = get_angle_to(get_global_mouse_position())
- if mouse_radians < 0:
- mouse_radians += PI + PI
- pass
- func set_sprite():
- sprite_sheet_hframes = $Sprite.hframes
- var target_sprite = Maths.scale(mouse_radians, 0, 2*PI, 0, sprite_sheet_hframes)
- $Sprite.frame = int(target_sprite)
Add Comment
Please, Sign In to add comment