0 votes

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
in Engine by (137 points)

1 Answer

0 votes

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

by (2,047 points)

thank you very much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.