I just upload a YouTube to show what happens. The first 16 second are mouse control, then I change to a Ps4 controller. From 16 seconds it shows the cursor as not smooth and unable to select on buttons, although they highlight.

I tried to fix it, but I don't have time tonight. The trick is to generate an input event when you press the gamepad button (not using the UI input mapping).

func _input(event):
	if event is InputEventMouseMotion:
		mouse_pos = event.position
	if event.is_action_pressed("pad_click"):
		var ev = InputEventMouseButton.new()
		ev.button_index = 0
		ev.pressed = true
		ev.global_position = get_global_mouse_position()
		Input.parse_input_event(ev)

But I couldn't get it to work, maybe I can check tomorrow or you can try to figure it out.

  • Mick replied to this.

    cybereality Thanks for the code I'll have a look when I get home tonight and see if I can figure it out. Will let you know...

    I found some code, which I've modified to try and get smoother Cursor Movement. Next I'll try to add to the original Cursor code...

    But then back to the X button click issue.....

    Make sure to do input processing in _input(): rather than _process(): unless absolutely necessary so that input events can happen and be process in between frames being rendered too.

    • Mick replied to this.

      cybereality

      Sorry I've not had much time due to work etc, I found the buttons still don't click to activate and lockup using the controller. I tried some changes below, but I still cant get the buttons to activate like using the hardware mouse. Just wondering if you had anymore ideas ?

      scene_tree is a variable.

      var scene_tree = get_viewport().get_tree()
      • Mick replied to this.

        cybereality

        Thanks....

        I think I've worked out an easy method to highlight and click on buttons using the controller and or mouse, I'll post it tonight after work.....

        So I created a Script for each of the buttons, then on each of the buttons I set under Node mouse_entered() and mouse_exited() then added the code to the three buttons. Now the Hardware Mouse has control or the Controller has control, and all buttons are clickable....

        12 days later

        So I've nearly finished the basic menu system, which I'll post up soon. The only issue I need to resolve is, if I use Viewport setting and keep aspect, in settings. The mouse position doesn't seem to work and controller doesn't work correctly.

        Does anyone know how to get mouse position only inside viewport ?

        I think get_local_mouse_position() will get the coordinates of the immediate parent.

        • Mick replied to this.

          cybereality

          Yeah I tried that this morning, but didn't fix the problem. I'll post the project file when I get home tonight. The mouse still works fine on changed viewport size, problem happens on controller input....

          I'm in Aussie, so I won't be home from work for another 6 hours doh!

          17 days later

          Bump.....

          Anyone have any idea on how to get the correct mouse position in viewport when the size changes. At the moment as soon as the viewport size is adjusted the mouse position no longer works, then the controller doesn't work correctly anymore ?

          What's the issue again?

          cursor.position = get_local_mouse_position()
          print(cursor.position)

          Using a print statement like that right after assigning that local mouse position there, I get values printed to the console that are clearly the correct mouse position.

          edit: ok, I think I know what your issue is. 🙂

          The sprite you use for the mouse cursor has it's pivot/origin at the center of the image. You want to have it moved over to the point of the arrow.


          Notice on the toolbar the icon in blue? That's the tool for moving the nodes origin/pivot point. In the above screenshot I've already moved it(the red-white cross) to the 'point' of the arrow, but when you open your project and highlight the cursor sprite node you'll see it's still in the middle of it.

          a year later

          Hi All, it's been a while since I've had a play with godot "4" but I'm hoping someone will have an answer for this. So I have a optionsButton and in the picture i have a sprite2d in front of it. the problem is when you open the drop down the sprite2d renders behind it, is there any way to hard code the render layer of the dropdown part of the optionsButton. It's pretty much a deal breaker for me, plus a few other issues with godot so I'm starting to sway back to the old Unity.