How to make a sword rotate xy degrees?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Czselu349

Hi there.
I’m trying to make a close ranged attack by rotating the weapon around.
(by global_rotation) Once a wise man said that everything with rotations is complicated XD. So I managed, to get the states working, but I don’t know why, but for some reason if I have the mouse at 0 angle (wich is on the left side) it’s kinda working, but not really, anywhere else it doesn’t even come close to what it should do. It should set the rotation back a bit and than make the rotation move forward. here’s a pic of how I imagine it:
image link

The code is here:

export(int) var slash_angle = 60 # In degrees, but it is converted to radians
export(float) var slash_speed = 0.25
var rotation_max_dist = 0.7 # max value of inaccuracy
var rotation_goal
var rotation_dir

# Slash attack for close range combat:
# -----------------------------------
func slash_attack_prepare(): #called at the first frame of attcking
 var mouse_rot = get_local_mouse_position().angle()
 rotation_goal =  mou + slash_angle / 2
 global_rotation = get_local_mouse_position().angle() - slash_angle / 2
 center.global_rotation = get_local_mouse_position().angle() - slash_angle / 2
 rotation_dir = sign(rotation_goal)

func slash_attack(delta): # called every frame of the attack
  if abs(rotation_goal - global_rotation) > rotation_max_dist:
    global_rotation += slash_speed * delta * rotation_dir
    center.global_rotation = global_rotation
:bust_in_silhouette: Reply From: deaton64

Maybe use the animation player?
GDQuest have a tutorial on YouTube to do that very thing.

thank you very much!

Czselu349 | 2020-08-30 21:01