Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LJ INFINITY |
So I made a slime script and the slime is supposed to come towards me but it goes the opposite direction I think it has to do something with my crappy knockback line
Here is my code:
extends KinematicBody2D
signal death
var hit = true
var health = 100
var health_max = 100
var health_regeneration = 1
var basic = false
var move1 = false
var move2 = false
var timer = 2
var run_speed = 55
var velocity = Vector2.ZERO
var player = null
var basic_hit_box = null
onready var anim = $AnimationPlayer
onready var sprite = $Node2D/main
onready var ded_sprite = $Node2D/ded
onready var attack_sprite = $Node2D/attack
func _ready():
ded_sprite.hide()
attack_sprite.hide()
hit = false
func _physics_process(delta):
velocity = Vector2.ZERO
if player:
velocity = position.direction_to(player.position) * run_speed
if player and hit == true:
velocity = position.direction_to(player.position) * -85
velocity = move_and_slide(velocity)
func _process(delta):
health = min(health + health_regeneration * delta, health_max)
if health <= 0:
velocity = 0
sprite.hide()
ded_sprite.show()
anim.play("ded")
emit_signal("death")
func _on_Area2D_body_entered(body):
player = body
func _on_Area2D_body_exited(body):
player = null
func _on_hitbox_area_entered(area):
basic_hit_box = area
anim.play("hit")
hit = true
health -= 7
func _on_hitbox_area_exited(area):
basic_hit_box = null
hit = false
func _on_AnimationPlayer_animation_finished(anim_name = "ded"):
if anim_name == "ded":
queue_free()
func _on_player_basic_damage(basic_damage):
health -= basic_damage
func _on_player_move1_damage(move1_damage):
health -= move1_damage
func _on_player_move2_damage(move2_damage):
health -= move2_damage