This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

In my scene I'm trying to dynamically add a rigid body with a collision capsule to a spatial scene. I have a static body collision plane below, so it works normally if I add the nodes in the scene tree through the editor, but not with code.

My coded rigid body shows having a collision capsule, but falls right through the plane. I hope that I'm overlooking something.

The code I have looks like this:

var rb =

var cs =



in Engine by (5,286 points)

You should write set_mode(RigidBody.MODE_CHARACTER) instead of set_mode(2), it's easier to understand and maintain :)

Neat, thanks. I see so you can use them like statics. I was wondering if there was a way to reach those constants from outside.

1 Answer

+1 vote
Best answer

CollisionShape is an editor helper, it's not really meant to be added as child during the game.
Instead, you should use add_shape:
Maybe this could fix your problem?

Edit: this works for me:

var body =
var shape =

However, I would recommend creating a scene rather than building objects from script, it's easier to do :)

by (29,510 points)
selected by

That's what it was. I remember reading about them being helpers, but I couldn't relocate the source.

The add and set shape didn't jump out at me as I was still thinking they were methods of the RigidBody class. But now that I'm looking again, I apparently glossed over that I was looking at the CollisionObject parent class and not the RigidBody.

Thanks for helping me clear that up. X)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.