+1 vote

I have been trying to make it so that I can create a cube and it will attach to whatever is passed into the function. But when I run it everything works fine, I can make towers of blocks, they collide, all of that but the joint doesn't do anything. I have tried various methods of creating and attaching the joint but nothing changes, I am not even getting errors.

Anyone have any idea what could be wrong?

#position = the position of new object, baseObject = a referance to the object that this 
one will be attacthed to.

func createObject(position,baseObject):
 position = position.snapped(Vector3(1,1,1)*gridScale)
 var object = RigidBody.new()
 var collision = CollisionShape.new()
 collision.shape = BoxShape.new()
 collision.shape.extents = Vector3(0.5,0.5,0.5)
 object.add_child(collision)
 object.translation = position
 var objectCSG = CSGBox.new()
 objectCSG.width = 1
 objectCSG.height = 1
 objectCSG.depth = 1
 object.add_child(objectCSG)
 $Creations.add_child(object,true)

 var joint = Generic6DOFJoint.new()
 baseObject.add_child(joint,true)
 joint.call_deferred("set_node_a",get_path_to(baseObject))

joint.calldeferred("setnodeb",getpathto($Creations.getchild($Creations.getchildcount()-1)))
#joint.setnodea(getpathto(baseObject))
#joint.setnodeb(getpathto($Creations.getchild($Creations.getchild_count()-1)))

Sorry about the weird indenting, but the text wrap is messing with it.

Godot version 3.3
in Engine by (468 points)

As a side note, it's recommended to avoid using CSG nodes when you're not performing boolean operations as their UV mapping is less flexible. Instead, use a MeshInstance with a CubeMesh resource assigned to its mesh property (this can be done via code too).

1 Answer

+1 vote
Best answer

Don't know why but replacing the code that adds the joint with this fixed it.

var joint = Generic6DOFJoint.new()
object.add_child(joint,true)
joint.set_node_a(object.get_path())
joint.set_node_b(baseObject.get_path())
by (468 points)
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.