大佬们,为啥我写的代码人物不会跟随鼠标移动啊。下面时代码
extends CharacterBody2D
@onready var playerAni = $ AnimatedSprite2D
var dir = Vector2.ZERO
var speed = 700
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var mouse_pos = get_global_mouse_position()
var self_pos = position
dir = (mouse_pos - self_pos).normalized()
velocity = dir * speed
move_and_slide()
pass