Any ideas on how make an interactible button in a 3d space

:bust_in_silhouette: Reply From: Wakatta

Node Tree Setup

â”–â•´Button3D (StaticBody)
    â” â•´Viewport
    ┃  ┖╴Button
    â” â•´Shape3D (CollisionShape)
    â”–â•´Sprite3D

Button3D Script

# Button3D.gd
extends StaticBody

func _ready():
    connect("input_event", self, "_on_Button3D_input_event")
    $Viewport/Button.connect("toggled", self, "_on_Button_toggled")
    $Viewport/Button.connect("pressed", self, "_on_Button_pressed")

func _on_Button3D_input_event(_camera, event, _position, _normal, _shape_idx):
	if event is InputEventMouseButton:
		if event.pressed:
			$Viewport/Button.emit_signal("pressed")
			$Viewport/Button.set_pressed(true)
		else:
			$Viewport/Button.set_pressed(false)

func _on_Button_pressed():
	print("pressed")

func _on_Button_toggled(button_pressed):
	print("toggled " + button_pressed )

Instructions

  1. Create a new ViewportTexture on Sprite3D and assign the Viewport in the above node tree
  2. Set the Viewport sizes to that of the Button node Rect size
  3. Change Shape3D shape to cover the Button area (BoxShape or PlaneShape)
  4. Connect the input_event signal of Button3D to the script above as seen in the _ready function
  5. Set Button toggle mode on
  6. Might have to set flipV on Viewport or Sprite3D node

Side Notes

There is actually a better way to get this done but if you’re lazy enough you can swap (Viewport, Button and Sprite3D) nodes for a Quad Meshinstance


â”–â•´Button3D (StaticBody)
    â” â•´Shape3D (CollisionShape)
    â”–â•´Sprite3D (MeshInstance)