Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dragonwarrior2004 |
extends KinematicBody2D
var max_health = 3
var health = max_health
var knockback = Vector2.ZERO
const SPEED = 100.0
func _physics_process(delta):
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
knockback = move_and_slide(knockback)
var direction = ($Player.position - position).normalize()
var motion = direction * SPEED * delta
position += motion
func _on_Hurtbox_area_entered(area):
var knockback_vector = area.knockback_vector
knockback = area.knockback_vector * 200
health -= 1
if health <= 0:
queue_free()
(Also, if I take out .position from $Player.position it helps that bug but causes another)
Edited: fixed your code formatting.
kidscancode | 2020-05-18 21:26