【问题标题】:How to make a 2D sprite follow mouse in Godot如何在 Godot 中制作 2D 精灵跟随鼠标
【发布时间】:2020-11-16 00:11:17
【问题描述】:

请提供在 Godot 中跟随鼠标的 Sprite 的最小代码示例。有复杂而大的示例项目,但我没有发现任何小而清晰的东西。

【问题讨论】:

    标签: godot


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多