KinematicBody click event

ozmosisozmosis Posts: 3Member
edited May 9 in 3D

I need a KinematicBody response to a click mouse, as I understand this is possible if the node has selected the property Input ray pickable and the function ** input_event**

My problems is nothing happen when click over the KinematicBody, there is not a call to the function, I' don't know if I missing something.

My treenode is:

      |__ MeshInstance

The script has implemented the function input_event connected with a signal from the Editor.

Is this possible to do or I need to change the type of the node?


Tags :


  • kryzmakkryzmak Posts: 100Member
    extends KinematicBody
    func _ready():
        self.connect("input_event", self, "_on_input_event")
    func _on_input_event(camera, event, click_position, click_normal, shape_idx):
        if event is InputEventMouseButton:

    You have to check as well which MouseButton it is.

  • ozmosisozmosis Posts: 3Member

    I already try this but still doesn't work. Could be necessary add an Area node to catch the event?

    I found this, is the same but in 2D, not fixed yet

    I'm using Godot 3.1.1


  • kryzmakkryzmak Posts: 100Member

    No extra action needed, just to make it clear: You have as well assigned a CollisionShape as a child node, right? Also take care that input_ray_pickable property of KinematicBody is TRUE

  • luan_ngoluan_ngo Posts: 2Member
    edited May 15

    Doesn't seem to work for me either. I'm using this code, which works but seems like overkill. I'm also on 3.1.1.

    # cast a ray from camera at mouse position, and get the object colliding with the ray
    func get_object_under_mouse():
        var mouse_pos = get_viewport().get_mouse_position()
        var ray_from = $Camera.project_ray_origin(mouse_pos)
        var ray_to = ray_from + $Camera.project_ray_normal(mouse_pos) * RAY_LENGTH
        var space_state = get_world().direct_space_state
        var selection = space_state.intersect_ray(ray_from, ray_to)
            return selection
  • MegalomaniakMegalomaniak Posts: 1,385Admin

    Sorry, I literally just woke up so I might be completely wrong on this but isn't there a missing if statement from somewhere in there..?

Sign In or Register to comment.