i writed a script for the sprite to loo at my mouse cursor but when i play the game it runs away from the cursor and goes crazy. this is the script i wrote:
extends KinematicBody2D
export var speed = 200
var smoothedmouse_pos: Vector2
func process(delta: float) -> void:
_smoothedmousepos = lerp(smoothedmousepos, getglobalmouseposition(), 0.3)
lookat(smoothedmouse_pos)
func physicsprocess(delta):
var direction = Vector2()
if Input.isactionpressed("up"):
direction += Vector2(0, -1)
if Input.isactionpressed("down"):
direction += Vector2(0, 1)
if Input.isactionpressed("left"):
direction +=Vector2(-1, 0)
if Input.isactionpressed("right"):
direction += Vector2(1, 0)
move_and_slide(direction * speed)