Godot Version
Godot 4.4.1
Question
Hello, I’m trying to make a game and am currently dealing with attacks. However, I’ve come across an error.
These are the errors:
Line 71:Expected statement, found “Indent” instead.
Line 72:Expected statement, found “Indent” instead.
Line 78:Expected end of file.
extends CharacterBody2D
class_name Player
signal healthChanged
var screen_size
var lastAnimDirection: String = "down"
var ishurt: bool = false
var isAttacking: bool = false
@onready var animations = $AnimationPlayer
@export var speed: int = 50
@export var maxhealth = 3
@export var knockbackPower: int = 500
@export var inventory: Inventory
@onready var currentHealth: int = maxhealth
@onready var effects = $Effects
@onready var hurttimer = $hurttimer
@onready var hurtColor = $Sprite2D/ColorRect
@onready var hurtbox = $hurtbox
@onready var weapon = $weapon
@onready var sprite = $Sprite2D
@onready var heartsContainer = $CanvasLayer/heartscontainer
func _ready():
effects.play("RESET")
func handleInput():
var moveDirection = Input.get_vector("ui_left","ui_right", "ui_up", "ui_down")
velocity = moveDirection*speed
if Input.is_action_just_pressed("attack"):
animations.play("attack" + lastAnimDirection)
isAttacking = true
await animations.animation_finished
isAttacking = false
func updateAnimation():
if isAttacking: return
if velocity.length() == 0:
if animations.is_playing():
animations.stop()
else:
var direction = "down"
if velocity.x < 0: direction = "left"
elif velocity.x > 0: direction = "right"
elif velocity.y < 0: direction = "up"
animations.play("walk" + direction)
lastAnimDirection = direction
func _physics_process(delta):
handleInput()
move_and_slide()
updateAnimation()
if !ishurt:
for area in hurtbox.get_overlapping_areas():
if area.name == "hitbox":
HurtByEnemy(area)
func HurtByEnemy(area):
currentHealth -= 1
if currentHealth < 0:
currentHealth = maxhealth
healthChanged.emit(currentHealth)
ishurt = true
knockback(area.get_parent().velocity)
effects.play("Blink")
hurttimer.start()
await hurttimer.timeout
effects.play("RESET")
ishurt = false
func _on_hurtbox_area_entered(area: Area2D):
if area.has_method("collect"):
area.collect(inventory)
func knockback(enemyVelocity):
var knockbackDirection = (enemyVelocity - velocity).normalized() * knockbackPower
velocity = knockbackDirection
print_debug(velocity)
print_debug(position)
move_and_slide()
print_debug(position)
print_debug(" ")
func _on_hurtbox_area_exited(area: Area2D): pass
The errors are in this specific parts:
func _physics_process(delta):
handleInput()
move_and_slide()
updateAnimation()
#Here, are 71 and 73
if !ishurt:
for area in hurtbox.get_overlapping_areas():
if area.name == "hitbox":
HurtByEnemy(area)
#And here is 78
func HurtByEnemy(area):
currentHealth -= 1
if currentHealth < 0:
currentHealth = maxhealth
healthChanged.emit(currentHealth)
ishurt = true
knockback(area.get_parent().velocity)
effects.play("Blink")
hurttimer.start()
await hurttimer.timeout
effects.play("RESET")
ishurt = false
What could be done?