Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ItzKillerTTV |
Hello! I am facing another issue.
I am making a top-down camera sort of game in which enemies go towards the player. However, after creating the knockback mechanic I quickly found out that the enemy didn’t actually recieve any knockback. I am unsure on how to fix this so I hope someone more experienced than myself could help me solve this.
This is the code in character.gd (all characters can take knockback):
func take_damage(dam: int, dir: Vector2, force: int) -> void:
hp -= dam
state_machine.set_state(state_machine.states.hurt)
velocity += dir * force
This is the code that makes the players weapon have a hitbox:
onready var dicesword_hitbox: Area2D = get_node("Dicesword/Node2D/AnimatedSprite/Hitbox")
This is the code that ads a knockback direction to the knockback:
func _process(_delta: float) -> void:
dicesword.rotation = mouse_direction.angle()
dicesword_hitbox.knockback_direction = mouse_direction
And this is the code from the enemy itself:
extends FiniteStateMachine
func _init() -> void:
_add_state("chase")
_add_state("hurt")
func _ready() -> void:
if state == states.chase:
parent.chase()
parent.move()
func _get_transition() -> int:
match state:
states.hurt:
if not animation_player.is_playing():
return states.chase
return -1
func _enter_state(_previous_state: int, new_state: int) -> void:
match new_state:
states.chase:
animation_player.play("melee_move")
states.hurt:
animation_player.play("hurt")
Please send help.