【发布时间】:2020-11-16 00:11:17
【问题描述】:
请提供在 Godot 中跟随鼠标的 Sprite 的最小代码示例。有复杂而大的示例项目,但我没有发现任何小而清晰的东西。
【问题讨论】:
标签: godot
请提供在 Godot 中跟随鼠标的 Sprite 的最小代码示例。有复杂而大的示例项目,但我没有发现任何小而清晰的东西。
【问题讨论】:
标签: godot
将Sprite节点放入场景中,并附加以下脚本。
const SPEED = 500
func _process(delta):
var vec = get_viewport().get_mouse_position() - self.position # getting the vector from self to the mouse
vec = vec.normalized() * delta * SPEED # normalize it and multiply by time and speed
position += vec # move by that vector
【讨论】: