请提供 Godot 中跟随鼠标的 Sprite 的最小代码示例。有复杂的和大的示例项目,但我没有发现任何小而清晰的东西。
将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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4423 次 |
| 最近记录: |