Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a HingeJoint2D node to complement HingeJoint3D #1033

Open
cheesymoo opened this issue Jun 10, 2020 · 10 comments
Open

Add a HingeJoint2D node to complement HingeJoint3D #1033

cheesymoo opened this issue Jun 10, 2020 · 10 comments

Comments

@cheesymoo
Copy link

Describe the project you are working on:
A 2D game featuring vehicles and trailer attachements

Describe the problem or limitation you are having in your project:
I would like to attach 2DKinematic or 2DPhysics bodies to each other via a 2D-HingeJoint

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
2D should have a HingeJoint, it is obviously useful as we have a 3D version of it already

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
It will be analogous to the 3DHingeJoint, just for 2D physics

If this enhancement will not be used often, can it be worked around with a few lines of script?:
I have attempted using other joints and scripting work-arounds, but nothing seems to have the desired effect

Is there a reason why this should be core and not an add-on in the asset library?:
It brings the 2D joints into parity with the 3D joints

@LinuxUserGD
Copy link

LinuxUserGD commented Jun 10, 2020

A 2D game featuring vehicles and trailer attachements

See former issue godotengine/godot#27901 for some simple 2d vehicle features, though the 2D HingeJoint might still be necessary to achieve a better effect.

@cheesymoo
Copy link
Author

Thanks for the response @LinuxUserGD
In our game the vehicles are top down. None of the other joints have the desired effect. The workaround I have done is to update the position of the trailer directly (in physics_process) based on the position of the vehicle.

This essentially breaks any collisions for the trailer, and generally seems to be THE WRONG WAY TO DO IT

But it is the best work-around I have mustered up

@pwab
Copy link

pwab commented Jun 12, 2020

As we have the PinJoint2D that only needs the addition of a max and min value of the rotation_degree (relative to a zero axis) what kind of implementation would this proposal mean?

  1. Only add such a feature to PinJoint2D
  2. Add the feature and rename the PinJoint2D to HingeJoint2D
  3. Add an extra HingeJoint2D with the same functionality as a PinJoint2D with the only difference that it is able of maintaining a max and a min value for the relative rotation

@cheesymoo would you specify this more clearly what you have in mind?


Just another workaround I used a few years ago:
Add another extra RigidBody and pin it to your car with the PinJoint that is used for the trailer plus another PinJoint to get it fixed. Remove collisions (and adapt collision layers/masks) so that only the trailer can collide with this extra body. If you now adapt the shape of the extra body you can control the rotation the trailer can make around the car.

grafik

@cheesymoo
Copy link
Author

cheesymoo commented Jun 12, 2020

@pwab Thanks for sharing your workaround!

As far as your 3 proposed implementations, any of those would satisfy my needs.

  1. Only add such a feature (max and min value of the rotation_degree) to PinJoint2D

This is great, it satisfies my needs and is simplest

  1. Add the feature and rename the PinJoint2D to HingeJoint2D

This is bad, because it removes existing nodes and could break other people's games

  1. Add an extra HingeJoint2D with the same functionality as a PinJoint2D with the only
    difference that it is able of maintaining a max and a min value for the relative rotation

This is the most ideal as it brings the 2D joints closer to parity with the 3D ones

So I am in support of your proposal 1 or 3. If the community/developers are not concerned about having 2D/3D parity between nodes, than I think 1 is the quickest/easiest solution

@MrZak-dev
Copy link

I really needed this to create a simple Knee animation in a Human Shaped RigidBody2D , we hope it will se some light in the coming Godot version .

@Calinou Calinou changed the title 2DHingeJoint Add a 2DHingeJoint node Nov 3, 2020
@pwab
Copy link

pwab commented Nov 3, 2020

Hey @MrZak-dev your knee animation should be a perfect fit for the IK-PR by TwistedTwigleg (godotengine/godot#40347). After building his working 2D branch you can simply open some of his samples here. He also implemented constraints with viewable debugging features. (TwoBoneIK should be the best for a human knee but you can also try the FABRIK algorithm for the whole lower limb which is basically the same thing I implemented here a few years ago.)

The PhysicalBone could be also another workaround for the problem @cheesymoo was facing. But I still think a 2DHingeJoint or simply the implementation of rotational constraints into the PinJoint2D could be a great benefit when dealing with such objects.

@vesk4000

This comment has been minimized.

@Calinou
Copy link
Member

Calinou commented Jun 16, 2021

@vesk4000 Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

@Calinou Calinou changed the title Add a 2DHingeJoint node Add a HingeJoint2D node to complement HingeJoint3D Mar 16, 2022
@Athakaspen
Copy link

The motor functionality of the 3D HingeJoint would also be very useful in 2D. I'm currently experimenting with a basic multijointed robot arm-esque model, and need a good way to apply torques around those joints.

@addmix
Copy link

addmix commented Jun 10, 2023

This functionality, and many other Joint2D related PRs would be solved by a 2D equivalent of the Generic6DOFJoint3D node.
These issues could all be solved by a generic Joint2D #4224 #86 #3891 #1033 #1423 #3704 (this one is only kinda solved by a generic joint).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants