Hi everyone! I have a problem 🙂 Somehow my enemys react to the Mouse and idk why. As you can see in the Video.everytime I move my mouse, the enemys move extremly fast and random. The mouse does not have a script and the enemy does move with move and slide.
The enemy Script
extends KinematicBody2D
export var Speed : float = 10.0
export var NavigationPath : NodePath = @"../../.."
export var Damage : int = 1
export var SteerForce : float = 10.0
export var KnockbackResistance : float = 8.0
export var Hp : int = 100
onready var Navigation : Navigation2D = get_node(NavigationPath)
var Velocity : Vector2 = Vector2.ZERO
var VelocityToTarget : Vector2 = Vector2.ZERO
var Steer : Vector2 = Vector2.ZERO
var Knockback : Vector2 = Vector2.ZERO
var Target : Node = null
var Path : Array = []
var NextPathPosition : Vector2 = Vector2.ZERO
func Spawn(target : Node):
Target = target
func _process(delta):
$Line2D.global_position = Vector2.ZERO
$Line2D.points = Path
if Target != null and Path:
MoveAlongPath()
Steer = lerp(Steer, (VelocityToTarget - Velocity) / SteerForce, delta)
Velocity += Steer
Velocity += Knockback
Velocity *= delta
Velocity *= Speed
Velocity.normalized()
move_and_slide(Velocity)
Knockback = lerp(Knockback, Vector2.ZERO, delta * KnockbackResistance)
$Velocity.position = Velocity #just for debug
$Steer.position = Steer
$Target.position = VelocityToTarget
func _on_RefreshPathToPlayer_timeout():
if Target and Navigation:
Path = Navigation.get_simple_path(self.global_position, Target.global_position)
func MoveAlongPath():
if Path.size() > 1:
NextPathPosition = Path[1]
VelocityToTarget = self.global_position.direction_to(NextPathPosition) * Speed
if self.global_position.distance_to(NextPathPosition) < 100:
Path.erase(0)
if not Path:
Target = null
VelocityToTarget = Vector2.ZERO
func GetDamage(damage : int, knockback : Vector2):
Knockback = knockback
Hp -= damage
if Hp <= 0:
self.queue_free()