How to rotate an object while moving it across an axis?

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

I’m trying to do a rudimentary spin attack with a sword by having the sword spin around my player. The problem is that when the sword moves past a certain point in the animation, it will rotate excessively in the wrong direction in order to match up with its rotation key.

I’ve narrowed this down to notice that it only happens when simultaneously rotating an object past a certain threshold (from negative to positive degrees or vice versa) and translating that object over an axis. It looks like the animation player is struggling to find the actual shortest path for the animation.

Here is a video recording of the behavior I am describing:

I found this question here, is the newest answer helpful? Looks like there was an issue once about it but it was closed and never re-opened or referenced again because it wasn’t categorized correctly… I didn’t see if anyone proposed it as a feature since this was closed.

DDoop | 2021-01-28 19:26

It’s very similar to what I’m asking, but I would like to be able to use the editor to solve this rather than code.

blurrred | 2021-01-28 19:59

:bust_in_silhouette: Reply From: Surtarso

you can set a fixed distance between your sword center and the player center so the sword can spin its center around the player center

func _set_sword_distance(): 
	var player_position: Vector2 = (player.global_position - global_position).normalized()
	var player_to_sword: Vector2 = sword.position - player_position
	var sword_direction: Vector2 = player_to_sword.normalized()
	var sword_vector: Vector2 = sword_direction * sword_distance
	var final_position: Vector2 = player_position + sword_vector
	sword.position = final_position

than you can rotate your sword freely and it will keep that same sword_distance and axis with the player no matter what he does

you will probably need to place the center of the sword node on its bottom so when it spins it looks right.

Surtarso | 2021-02-26 00:46