Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I detect where the player clicks ? #418

Open
Naeta2 opened this issue Dec 29, 2023 · 3 comments
Open

How can I detect where the player clicks ? #418

Naeta2 opened this issue Dec 29, 2023 · 3 comments
Labels
question Further information is requested

Comments

@Naeta2
Copy link

Naeta2 commented Dec 29, 2023

I am using the plugin to generate a world map, it is great thank you for it

I was trying to detect where the player mouse is relative to the terrain, I enabled collision but I can't find how to get a signal when the player mouse is on the terrain with data of where it is located. How can I access collision signals ?

Thank you

@Zylann
Copy link
Owner

Zylann commented Dec 29, 2023

Instead of signals, you can try using a raycast? See https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html

@Zylann Zylann added the question Further information is requested label Dec 29, 2023
@ElectronicRU
Copy link

The terrain collider still calls set_ray_pickable to false despite the bug it works around being fixed in Godot 3.1. Maybe terrain can be ray-pickable now and we can have input_event support?

@Zylann
Copy link
Owner

Zylann commented Jan 21, 2024

I would still recommend using a raycast, because it offers similar functionality that works already.

Adding a ray_pickable property requires a extra work for a similar result which is more for convenience: it would require the terrain to also provide an _input_event, _mouse_enter, _mouse_exit methods, maybe also a capture_on_drag.

Unfortunately, it looks like the scripting API doesn't expose enough things for the plugin to offer the same functionality easily. For example, implementing _input_event_call requires to implement a C++ virtual method CollisionObject3D::_input_event_call which doesn't exist in GDScript. The plugin uses PhysicsServer3D directly, which does not provide the input callbacks part. Also, when you set ray_pickable to true, Godot's input system looks for a CollisionObject3D: https://github.com/godotengine/godot/blob/0bcc0e92b3f0ac57d4c4650722f347593a258572/scene/main/viewport.cpp#L900 Which means it wouldn't work with the terrain node, it is custom.
The collision part would have to be completely re-implemented using nodes instead, just for that convenience feature...

On a side note, it seems GridMap and TileMap nodes (similar "terrain" nodes) could have the same issue in Godot itself. They don't have ray_pickable functionality, likely for the same reason.
I could only find this proposal for GridMap, but it only fixes GridMap, it doesn't acknowledge the fact this is a general issue with all nodes that manage collision internally rather than relying on CollisionObject3D nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants