Godot Version
``extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var combatmode = false
@onready var health = 100
@export var timer : Timer = null
@onready var anim = $AnimatedSprite2D
var cooldown_active : bool = false
func _ready()->void:
timer.timeout.connect(_on_timer_timeout.bind())
func _on_timer_timeout() → void:
cooldown_active = false
func _physics_process(_delta: float) → void:
if Input.is_action_just_pressed("combat"):
print(cooldown_active)
if cooldown_active == true:
return
elif combatmode == false:
combatmode = true
cooldown_active = true
combat()
timer.start()
else:
combatmode = false
cooldown_active = true
combat()
timer.start()
if Input.is_action_just_pressed("hit"):
punch()
look_at(get_global_mouse_position())
var directionx := Input.get_axis("left", "right")
var directiony := Input.get_axis("up", "down")
if directionx:
velocity.x = directionx * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if directiony:
velocity.y = directiony * SPEED
else:
velocity.y = move_toward(velocity.y, 0, SPEED)
move_and_slide()
func combat():
if combatmode == true:
print(“hi”)
anim.play(“combat”)
else:
anim.play(“Idle”)
func punch():
if combatmode == true:
anim.play(“Punch”)
Im trying to do healthbar with player, but it rotates with the player. I tried to make the sprite look at mouse direction but it always looked 90 degrees to different location`
