I don't get whats wrong and my game is crashing each time I do it.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PizzaPilot2000

I’m new to Godot so Ive been following this (https://www.youtube.com/watch?v=mAbG8Oi-SvQ&list=PL9FzW-m48fn2SlrW0KoLT4n5egNdX-W9a) tutorial by Heartbeast on YouTube. I’m on part 13 which is on knockback and enemies, but after I type up the code and attack the enemy, the game crashes. Not sure what I’m doing wrong, so hopefully someone can help. Scripts are enclosed below:

ENEMY SCRIPT:
extends KinematicBody2D

var knockback = Vector2.ZERO

func _physics_process(delta):
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
knockback = move_and_slide(knockback)

func _on_Hurtbox_area_entered(area):
knockback = area.knockback_vector * 120

PLAYER SCRIPT:
extends KinematicBody2D

const FRICTION = 500
const ACCELERATION = 500
const ROLL_SPEED = 125
const MAX_SPEED = 80

enum {
MOVE,
ROLL,
ATTACK
}

var velocity = Vector2.ZERO
var state = MOVE
var roll_vector = Vector2.LEFT

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get(“parameters/playback”)
onready var swordHitbox = $HitboxPivot/SwordHitbox

func _ready():
animationTree.active = true
swordHitbox.knockback_vector = roll_vector

func _physics_process(delta):

match state: 
	MOVE:
		move_state(delta)
	ROLL:
		roll_state(delta)
	ATTACK:
		attack_state(delta)

func move_state(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
input_vector.y = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
input_vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
	roll_vector = input_vector
	swordHitbox.knockback_vector = input_vector
	animationTree.set("parameters/Idle/blend_position", input_vector)
	animationTree.set("parameters/Run/blend_position", input_vector)
	animationTree.set("parameters/Attack/blend_position", input_vector)
	animationTree.set("parameters/Roll/blend_position", input_vector)
	animationState.travel("Run")
	velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
	
else:
	animationState.travel("Idle")
	velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

move()

if Input.is_action_just_pressed("roll"):
	state = ROLL

if Input.is_action_just_pressed("attack"):
	state = ATTACK

func roll_state(delta):
velocity = roll_vector * ROLL_SPEED
animationState.travel(“Roll”)
move()

func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel(“Attack”)

func move():
velocity = move_and_slide(velocity)

func roll_animation_finished():
velocity = velocity * .9
state = MOVE

func attack_animation_finished():
state = MOVE

SWORD HITBOX:

extends Area2D

var knockback_vector = Vector2.ZERO

Once again, not sure what I’m doing wrong, and any help would be greatly appreciated. Thanks in advance.

Post the error message that godot gives you when it crashes

timothybrentwood | 2021-08-05 22:20