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
- Create a new ViewportTexture on Sprite3D and assign the Viewport in the above node tree
- Set the Viewport sizes to that of the Button node Rect size
- Change Shape3D shape to cover the Button area (BoxShape or PlaneShape)
- Connect the
input_event
signal of Button3D to the script above as seen in the_ready
function - Set Button toggle mode on
- 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)