Godot Version
Godot 4
Question
I can’t find my setter function on Animation player
extends CharacterBody2D
@export var health = 100
@export var acd = 2
@onready var yudi: CharacterBody2D = $"."
@onready var dash = $Dash
@onready var timer = $Att_CD
var basespeed = 300.0
var can_attack : bool = true
var _is_attacking := false:
set(value):
_is_attacking = value
const dashspeed = 750
const dashlength = .2
func _physics_process(delta: float) -> void:
var direction_x := Input.get_axis("left", "right")
var direction_y := Input.get_axis("up", "down")
#print(position-get_global_mouse_position())
#print("player pos", position)
#print("mouse pos", get_global_mouse_position())
if position > get_global_mouse_position():
$Sprite2D.flip_h = true
$Sprite2D/Hitbox/CollisionShape2D.position.x = -60
#print("right")
else :
$Sprite2D.flip_h = false
$Sprite2D/Hitbox/CollisionShape2D.position.x = 60
#print("left")
if Input.is_action_just_pressed("dash"):
can_attack = true
dash.start_dash(dashlength)
var SPEED = dashspeed if dash.is_dashing() else basespeed
if direction_x:
velocity.x = direction_x * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction_y:
velocity.y = direction_y * SPEED
else:
velocity.y = move_toward(velocity.x, 0, SPEED)
if Input.is_action_just_pressed("spasi") and can_attack:
$AnimationPlayer.play("attack_front")
can_attack = false
timer.attacked(2)
velocity = Vector2.ZERO
velocity = (get_global_mouse_position() - position) * delta * 150
await $Att_CD/Att_Timer.timeout
print("can attack")
can_attack = true
if velocity.x != 0 and $AnimationPlayer.current_animation != "attack_front":
$AnimationPlayer.play("walk_front")
elif velocity.y != 0 and $AnimationPlayer.current_animation != "attack_front":
$AnimationPlayer.play("walk_front")
else :
if $AnimationPlayer.current_animation != "attack_front":
$AnimationPlayer.play("idle")
#player_movement(delta)
if not _is_attacking:
move_and_slide()
Am I doing this wrong?
Thank you in advance