gpt4 book ai didi

godot - 如何在 Godot 中让 2D Sprite 跟随鼠标

转载 作者:行者123 更新时间:2023-12-03 08:32:01 24 4
gpt4 key购买 nike

请提供 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

关于godot - 如何在 Godot 中让 2D Sprite 跟随鼠标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64846699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com