-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Missing CollisionObject input_event integration. #16
Comments
If I understand correctly this is similar to what happens with the buttons discussed in PR #19. I think this is something that should be fixed in the Godot engine itself. But for now I like your idea of using a raycast. I don't have much experience developing 3D games in godot but I put together something basic that should work, if you want to try it add the following code to the if "position" in val:
var camera = get_viewport().get_camera()
var from = camera.project_ray_origin(val.position)
var to = from + camera.project_ray_normal(val.position) * (camera.far)
var root = get_tree().get_root()
if root is Node:
var inter = root.get_world().direct_space_state.intersect_ray(from,to)
if !inter.empty():
inter["collider"]._input_event(camera, val, inter["position"], inter["normal"], inter["shape"]) Also here is an example project I used for testing: example.zip Some comments about the code:
|
I am running into this issue in my 2D project. I planned on using the SingleTouch/SingleTap events on an Area2D input_event() instead of using the button nodes (mouse emulation) since my project is mobile only. I'm assuming the raycast solution is only relevant in a 3D project? Maybe I'm approaching this incorrectly but my goal was just to make my own buttons that use the GTIM events. |
Mouse emulation and button nodes should work even if your project is mobile only, but maybe you have another reason. The raycast solution, as far as I know, is not useful in 2D, but in 2D it's not that hard to do it manually. I mean you need the coordinates of the 4 vertices that define the Area2D (assuming it's a rectangle) and then with that you can check if the position of the event is inside the Area2D. I'm not sure if it makes a difference, but you should also be able to do this kind of manual detection with the button nodes, in fact all you need is 4 dots describing a rectangle. |
Could you port this solution to Godot 4? I tried the code below:
But I get the following error: Invalid call. Nonexistent function '_input_event' in base 'StaticBody3D'. |
I've found this project incredibly helpful for building the mobile/touch camera input for my 3D project. I wanted to use the SingleTouch/SingleTap events for selecting objects in the scene howevever the events don't appear to propogate through to the
CollisionObject
input_event
signal.https://docs.godotengine.org/en/stable/classes/class_collisionobject.html
I've had a look through the Readme here and also at the Godot documentation, there doesn't appear to be a simple way to enable this.
Here's two ideas on how this could be achieved:
_input_event
on the collider._input_event
handler (leveraging the existing raycasts), for example:The text was updated successfully, but these errors were encountered: