0 votes

In 3D I'm trying to click on a StaticBody and using inputevent.

With

Input.MOUSE_MODE_VISIBLE

I can click on the StaticBody and create something where the click happened.

With

Input.MOUSE_MODE_CAPTURED

I get no mouse events in the StaticBody for _input or _input_event.

How can I find out where a StaticBody was clicked when in Input.MOUSE_MODE_CAPTURED?

in Engine by (14 points)
edited by

1 Answer

0 votes

Check to make sure you have a suitably sized collision shape added to it, and that the StaticBody has the option Ray Pickable turned on.

After that click events from the viewport should cast rays that are received and reported to the StaticBody's _input_event(), the received parameters will tell you everything you need to know about the collision.

func _input_event(camera, event, click_pos, click_normal, shape_idx):
by (5,190 points)

Which works has long I have:

Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

However as soon as I set it to:

Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

Input invents on my StaticBody no longer are triggered when the mouse clicks/moves

I will experiment some more but haven't been able to get it to work.

Hmm, sorry, I've never tested such a thing.

It says it continues to track movement, maybe it's not a compatible thing.

If you're able to track to the motion and clicks with regular input events, then you can cast your own rays.

The camera can give you a unprojected ray normal, based on the viewport coordinates.

You can put a RayCast node on the camera and call something like this, and then test the ray intersection in the fixed_process.

my_ray.set_cast_to(my_camera.project_ray_normal(event.pos) * ray_length)

Or you can also store the coordinates, and during the fixed_process grab the world state and use the PhysicsServer to cast a ray.

func _fixed_process(delta):

    var state = get_world().get_direct_space_state()
    var intersections = state.intersect_ray(from_vector, to_vector)

Yep, so _input started working. Not sure what I changed that changed that. Maybe I was just reading it wrong. With _input reading mouse clicks I am able to read a ray parented under the player camera. I can get what it intersects with as well as the position where it intersects. _input_event is now useless but I've been able to recreate the behavior.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.