This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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:
_smoothed
mousepos = lerp(smoothedmousepos, getglobalmouseposition(), 0.3)
look
at(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)
Godot version 3.4.4
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.