Explanation of physical objects that can't move autonomously but can be handled with visual scripting

While experimenting with various approaches, I discovered that while you cannot directly control a GameObject with Visual Scripting, you can implement a GameObject in code that moves via physics and uses Visual Scripting for logic such as collision detection. I’d like to share this solution.

Please note that this is just a proof of concept; further validation would be needed before it could be considered practical for real-world use.

◆ Main GameObject
go_physics_controller.zip (6.6 KB)

◆ File Contents


The custom content consists only of GOcontroller and its script.
When you load this object and place it in the scene, it bounces around. Additionally, Visual Scripting is configured so that the object disappears upon colliding with any other object.

The physics behavior is set up using RigidBody2D and its child CollisionShape2D.
By adjusting properties in RigidBody2D, such as mass and overriding the physics material (friction, bounce), you can change how it bounces.

◆ Brief Explanation of the GDScript
This implementation works by forcibly reflecting the movement of Godot’s physics object, RigidBody2D, onto its parent node, GameObject.

Normally, the movement of child nodes does not affect the parent node. If you simply make RigidBody2D a child, it will drift away from the parent independently. However, by applying this script, they move together.

◆ Notes

  • The layer for this GameObject is set to 2, and the mask is also 2. Be mindful of layers if you want other objects to detect collisions with it.
  • Conversely, the layer for RigidBody2D is set to 1, and its mask is also 1.

◆ Example Use Cases

  • Physical objects that trigger certain actions when touched by the player.
  • Physical debris that deals damage.
    And so on. (Probably.)

◆ Advanced Application Ideas

  • If you can effectively use add_force in scripts or make good use of AnimatableBody2D, it might become possible for the player to push this object.
1 Like