+1 vote

I see the question was asked a couple of times for 2d and it seems there are some solutions for that. But how to do it in 3d?

First I thought that a mere CollisionShape.new() and a setshape to it with an addchild to my kinematicbody was working, but I noticed that when the scene had before a collisionshape created in the editor and then it was deleted, the collisionshape is still used, leading me to the false idea that my code was working.

I tried to use KinematicBody.add_shape() but Godot is crashing right away when I play the scene.

in Engine by (697 points)

1 Answer

+1 vote
Best answer

It's the same API in 3D. Shapes used for collision are not nodes, you don't need to add a child in any way (which is only an editor convenience) or creating CollisionShape either. Adding a shape to a physical object from a script is done with add_shape and related methods, and the shapes you can add are different classes: http://docs.godotengine.org/en/stable/classes/class_shape.html#class-shape

If Godot crashes (error? or real crash?) when you use add_shape, it's probably a bug that you can report on Github if you have a minimal project that shows it. Or maybe you tried to add a shape that actually was a CollisionShape node, and you ran into Godot not understanding what was going on.

by (27,897 points)
selected by

You were right. Thanks for the fast answer. Indeed my mistake was to give a collisionshape node in add_shape. Strange enough, Godot doesn't give any error message. It only ends the game right away.

Now I have to figure out how to set the translation of my shape. Because I have 2 shapes to create and they are at a specific place, which I must even move later in the game. And those shapes objects have no transform field. I'll probably have to ask a new question for that new problem.

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 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 webmaster@godotengine.org with your username.