Generic6DOFJoint (Spring)

aalvaalv Posts: 2Member

I am trying to implement a spring with the node Generic6DOFJoint.
Generic6DOFJoint has a Spring property, but I can't seem to get it to work and from my research I haven't found any tutorial, example implementation or other support on the Generic6DOFJoint node.
Can someone help me.
Thanks.

Comments

  • dotteddotted Posts: 258Member
    edited April 14

    I will outline what I do in a couple posts, starting here:

    (recommended)
    You connect two RigidBodies to a Joint. Because these elements are under the control of Bullet, they should not be the children of any scene subtree subject to a transform change. In short none of these elements should be node children of each other.

    I use an assembly Spatial (for 3d work) to organize an assembly of bodies and their joint (s), like so:

    • AssemblyNode
      • Body1
      • Body2
      • Joint

    The reason to place the joint after the bodies is to prevent godot spamming warnings that a joint lost the bodies it was bound to if this scene subtree is deleted. Being the last child, it is deleted first, removing the complaint. If the bodies are deleted first, you'll get a warning spam storm.

    Using an assembly makes it easy to place the collection when added to a scene. Just be sure not to casually (read not after setup) change AssemblyNode's transforms after. The consequence can be that the objects behave a bit erratically because you have changed the position of these elements and Bullet is not aware. This messes with its simulation for a few frames.

    (next setup)

  • dotteddotted Posts: 258Member
    edited April 14

    The first thing you'll want to do in your scene is to get the node_a and node_b of the Joint to reference Body1 and Body2 respectively.

    Here I will use RigidBody for both body1 and body2 to keep things as simple as possible. This example will model body2 being effected by a y-axis spring (Y axis only)

    Give them spherical collision shapes (again for simplicity here). Set their sizes as you see fit and give them some visual aspect with MeshInstance or CSGShape and maybe a shader.

    As a development step, set Body1 mode to STATIC, Body2 (RIGID). Place Body1 over Body2 and so they are separate and Body2 has room to fall. This setup makes Body1 like a fixed hanger (because of the STATiC mode) and body2 the moving body (RIGID body mode).

    Now, configuring the 6DOF part:

    Joints represent a 'pivot' or reference frame around for its constraints and degrees of freedom. All the movement configured for 6dof is relative to this reference frame.

    I usually think of placing it with respect to node_b. Here, placing it in the middle of the space between body1 and 2 is fine.

    This joint by default is set up as 'rigid', that is like the two bodies pinned together by an invisible beam (the joint constraints), and you configure the joint's degrees-of-freedom fields to allow motion you want.

    In this example, disable linear_limit_y. This will allow body2 to move freely along the joints y-axis. (later you can experiment with linear_limit_y to 'box-in' the spring motion if you want, but later)

    (note that I think bullet configures the joint axis internally and "up" is defined as going from body1 to body2.)

    Now go to linear_spring_y and enable it. You will notice 3 other properties in the spring_y inspector fold-out.. or whatever it is called.

    The three values determine the overall characteristics for the spring.

    So if you know the basics of spring physics, there is the notion of the rest-point (equilibrium) and this is the point where the spring exerts no forces. Stiffness refers to what is known as the 'restoring' force applied when there is deviation from this rest position.

    The force applied is proportional to the amount of displacements from the equilibrium point.

    Damping is a 'viscosity' factor that works against motion in the spring's axis. You can use it to prevent the bodies from gaining too much velocity for your purposes.

    So with this in mind, play with the set up (run it), maybe label all the bodies and the joint as 'tool' since i think then you can modify in the editor and see what happens.

    Since body2 is under the influence of 1 g of gravity, it will sink down a bit and maybe bobble and slowly come to rest (because damping).

    If you play with the equilibrium point, body2 will 'sink' or 'rise' accordingly.
    If you play with stiffness, body2 will sink less and will move more sharply when equilibrium changes (or if body2 is pulled up or down).
    If you play with damping body2's max velocity from stiffness/applied force will be effected.

    Next steps:

    Put floor under this assembly and make body1 a rigid body and play with the behavior.

    Enable linear_limit_y and set up the upper and lower limits (think upside down). Godot's editor feed back is a bit wonky in my opinion but play with upper and lower separately a little to get an idea of how they work.

  • dotteddotted Posts: 258Member

    Lastly you can set body1 to kinematic-mode and add some scripting to move that body around to explore the spring physics.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file