Attention | Topic was automatically imported from the old Question2Answer platform. | |
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