Hello, pretty new to GDScript and Godot. Using RC1 of Godot 4 currently.
I have an enemy that follows a path, but when it spots you it will go after you. Now I've been trying to implement knockback (once I attack the enemy) but I can't get anything to work, and I assume it's because of how I do the navigation movement. Here's the code where move_and_slide() is called:
func MoveTowardsPoint(delta, speed):
var targetPos = nav_agent.get_next_path_position()
var direction = global_position.direction_to(targetPos)
faceDirection(targetPos)
velocity = direction * speed
move_and_slide()
if playerInSightClose:
CheckForPlayer()
print("Werkin Close")
if playerInSightFar:
CheckForPlayer()
print("Werkin Far too yay")
Ang here is how a piece from shrtsword.gd script which handles how I deal damage using the weapon... for the moment at least:
func _on_hitbox_body_entered(body):
if body.is_in_group("Enemy"):
$AttackAudio.stream = random_snd_attack[randi() % len(random_snd_attack)]
$AttackAudio.play()
print("enemy hit")
body.take_damage(10)
The sword has a three hit combo set up too above this part. If I could get the knockback going generally, I will redo it later to happen on the third hit. But I digress. I Would appreciate at least some tips on how to handle my problem. Thank you.