Beginner with Godot. I have a “TriangleProjectile” scene that consists of:
Rigidbody2D
CollisionShape2D
Sprite2D
The Rigidbody2D has the following script attached:
extends RigidBody2D
func _ready():
input_pickable = true
func _input_event(viewport, event, shape_idx):
print("EVENT: ", event)
if event is InputEventMouseButton and event.pressed:
queue_free()
When I run the scene, the code works fine, but once I instantiate the scene in my MainScene, no input whatsoever is detected. I tried parenting the instances to different parents, created a “TopLayer” parent that is at the bottom of the tree (to not be blocked by anything) and tried everything I or the AI can think of, but it just doesn’t work. I’m kinda going insane here…
Make sure that the input isn’t being consumed by a Control node by checking the tab Misc inside the Debugger dock. The field Clicked Control will show you the latest Control node that was clicked.
Another option is that you disabled the input in the game. Make sure that the Input button is pressed in the Game embedded window.
Thank you for your reply!
The “Game” Window is not available on my OS (MacOS), but the input button is definitely active (to clarify, its available but shows the message “Game embedding not available on your OS”)
In regards to the control node: I just have one, the GameScreen is the control node and parent for the other nodes:
But the root node type depends on what your scene represents. For example, for a character that will interact with the physics system (a platformer player, an enemy,…) then a better root node would be a CharacterBody2D or RigidBody2D as these nodes interact with the physics system and let you control them. For a collectible like a coin or a heart or elements that hurt the player like spikes or poison then an Area2D would be better because this node let you know when something (a physics body or another area) enters or exits the area using its signals.
You can check the tutorial Your first 2D game in the documentation for a more information.