检测godot内3d对象上的点击/触摸屏输入

时间:2019-10-30 14:55:58

标签: godot

我正在尽力在godot游戏引擎中构建手机游戏。而且我遇到了一个问题。在3D游戏中,我如何检测鼠标单击特定对象或该对象在屏幕上的位置。我不明白如何使用控制节点来做到这一点。

1 个答案:

答案 0 :(得分:0)

使3D对象可点击的最简单方法是给它一个CollisionObject(例如StaticBody)并连接到input_event信号。例如,要检测左键单击:

extends StaticBody

func _ready():
    connect("input_event", self, "on_input_event")

func on_input_event(camera, event, click_position, click_normal, shape_idx):
    var mouse_click = event as InputEventMouseButton
    if mouse_click and mouse_click.button_index == 1 and mouse_click.pressed:
        print("clicked")

docs提到触摸事件类似于点击事件。

请注意,input_ray_pickable必须是true上的CollisionObject(默认设置)。