GithubHelp home page GithubHelp logo

Comments (4)

Federico-Ciuffardi avatar Federico-Ciuffardi commented on May 20, 2024 2

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.

Federico-Ciuffardi avatar Federico-Ciuffardi commented on May 20, 2024

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 the direct_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.

JeffBusch avatar JeffBusch commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.