Comments (4)
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.
from godottouchinputmanager.
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 _emit
method in InputManager.gd:
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:
- The ray must have a length. I used
camera.far
because I assume that is a reasonable length. - I check if the root of the tree is a
Node
to check if the scene is 3D before trying to get thedirect_space_state
but I don't know if there is a better way to do it (there probably is). - The code can also be placed in the
_input
or_unhandled_input
method of another node where it must only be executed if the processed event is non-native. This has the advantage of not being specific to GDTIM custom events.
from godottouchinputmanager.
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.
from godottouchinputmanager.
Related Issues (20)
- Condition "!is_visible_in_tree()" is true HOT 1
- Tapping quick does not register as tap. And Pinch/Twist constantly switching to Multiple finger drag. HOT 9
- Only works on the edges of the screen when using a Control Node instead Node2d HOT 5
- Support LongPress gesture. HOT 1
- Invalid get index '0' on InputEventSingleScreenLongPress HOT 15
- InputEventMultiScreenDrag fingers not reset HOT 1
- Godot 4 Support HOT 6
- InputEventMultiScreenTap - Feature Request HOT 2
- single_taps not recognized after resuming from pause menu HOT 2
- multi_tap arbitrary distance support HOT 2
- it's not working in godot 4 beta HOT 1
- Memory Leaks at RawGesture.gd and Util.gd HOT 3
- Swipe, tap input not received when use get_tree().paused on Mobile device HOT 2
- Suggestion: any_tap signal HOT 2
- Implement a Pan gesture HOT 1
- Not working with Godot 4.2.1 HOT 9
- Inconsistent usage of event attributes HOT 3
- Pinch not working when over buttons. HOT 3
- Method for detecting swipe release HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godottouchinputmanager.