It's supposed to detect which direction the mouse is headed to from the players perspective and get a gun out from that direction. I've been trying so hard to fix it. I'd also really appreciate any tips on how could I improve this code.
if Input.is_action_pressed("MouseClick"):
var mousePos = get_local_mouse_position()
var direction : String
if $Weapon.offset.y == 0:
if abs(mousePos.x) - abs(mousePos.y) >= 0:
if mousePos.x >= 0:
direction = "right"
$Weapon.rotation_degrees = 90
else:
direction = "left"
$Weapon.rotation_degrees = -90
else:
if mousePos.y <= 0:
direction = "top"
$Weapon.rotation_degrees = 0
else:
direction = "bottom"
$Weapon.rotation_degrees = 180
while Input.is_action_pressed("MouseClick") and direction == get_direction_changed():
print(direction)
if $Weapon.offset.y >= -188:
$Weapon.offset.y -= 4
$WeaponGetOut.start(0.1)
yield($WeaponGetOut, "timeout")
else:
$Weapon.play("MinigunSpin")
if $Weapon.speed_scale < 60:
$Weapon.speed_scale += 0.05
$WeaponGetOut.start(0.1)
yield($WeaponGetOut, "timeout")
while (!Input.is_action_pressed("MouseClick") or direction != get_direction_changed()) and $Weapon.offset.y != 0:
get_back_in()
$WeaponGetOut.start(0.1)
yield($WeaponGetOut, "timeout")
else:
get_back_in()
$WeaponGetOut.start(0.1)
yield($WeaponGetOut, "timeout")
func getbackin():
if $Weapon.speed_scale > 3:
$Weapon.speed_scale -= 0.1
else:
$Weapon.playing = false
if $Weapon.offset.y != 0:
$Weapon.offset.y += 4
func getdirectionchanged():
var mousePos = get_local_mouse_position()
if abs(mousePos.x) - abs(mousePos.y) >= 0:
if mousePos.x >= 0:
return "right"
else:
return "left"
else:
if mousePos.y <= 0:
return "top"
else:
return "bottom"