![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | adda820 |
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 _smoothed_mouse_pos: Vector2
func _process(delta: float) → void:
_smoothed_mouse_pos = lerp(_smoothed_mouse_pos, get_global_mouse_position(), 0.3)
look_at(_smoothed_mouse_pos)
func _physics_process(delta):
var direction = Vector2()
if Input.is_action_pressed(“up”):
direction += Vector2(0, -1)
if Input.is_action_pressed(“down”):
direction += Vector2(0, 1)
if Input.is_action_pressed(“left”):
direction +=Vector2(-1, 0)
if Input.is_action_pressed(“right”):
direction += Vector2(1, 0)
move_and_slide(direction * speed)