kong   喵Ta  
 
脚本编程 
大佬们,为啥我写的代码人物不会跟随鼠标移动啊。下面时代码
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
   
[投稿须知]
投稿邮箱:hareqj@163.com
教程投稿:可提供B站视频BV号,会直接生成视频播放页。
游戏投稿:须原创,请提供 作品web版文件、作者、简要操控说明。
内容举报邮箱:hareqj@163.com,请告知内容编号(右上角)及违规说明。
Copyright Godot社区 Godot2D.com All Rights Reserved.
京ICP备13032831号