Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

PinJoint2D angle limits work incorrectly if NodeB parent node turns 180 degrees. #69

Open
tomsep opened this issue Nov 17, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@tomsep
Copy link

tomsep commented Nov 17, 2023

Describe the bug
If PinJoint2D has limits enabled with the following node hierarchy

Scene
- NodeA (RigidBody2D)
  - PinJoint2D
  - NodeB (RigidBody2D)

then when NodeA node turns over 180 degrees the PinJoint2D will lose track of where the limits are and begin spinning.
However, if NodeB is not child of NodeA then the limits will work correctly.

image

To Reproduce
Using the attached project turn the box around with left/right keys. When turned 180 degrees it should fail.

Expected behavior
Expected that the physics behavior is not affected by the node hierarchy.

Project
PinJointAngleBug.zip

Versions (please complete the following information):

  • OS: Windows
  • Godot v4.2 beta6
  • Box2d v0.9.0
@tomsep tomsep added the bug Something isn't working label Nov 17, 2023
@Ughuuu
Copy link
Collaborator

Ughuuu commented Nov 18, 2023

Uh, this seems like a very tricky case. Am wondering what Godot does in this case for rigidbodies parented.
Anyway, I don't see a good use case for it anyway, I think you just shouldn't parent a rigidbody to another. Will ask around on the Godot Chat to see what happens in Godot when you do this(parent rigidbody with child rigidbody)

@tomsep
Copy link
Author

tomsep commented Nov 18, 2023

While this can be mostly avoided by not parenting NodeB to NodeA it might cause headache when trying to structure your scene. For example, when you want to combine multiple RigidBody2D based scenes to create a new scene.

When using Godot default physics the joint limits seem to always be relative to global origin. So, regardless of the "Cube"s orientation the "Antenna" will always point world up as the joint limits are set to [-10, 10]. I don't think that is good behavior but not sure if it is a bug or not.

@Ughuuu
Copy link
Collaborator

Ughuuu commented Nov 18, 2023

Ok, while true it doesn't work, I would be careful anyway using this way. Rigidbodies should be separate. If you group them as you do, eg RigidbodyA parent and RigidbodyB child,
RigidbodyB will have its set_transform method called every frame. While it might be performance intensive, that's not that important really as it is that it's setting its transform instead of using the velocity. So the physics simulation quality will suffer also, resulting in a lot of jitter.

If you want to group Rigidbodies, I suggest having a parent Node2D for both Rigidbodies and create a scene with those, but dont have child Rigidbodies.

As for this bug, it seems that every time the body position is changed, the reference angle should be updated somehow too I guess, will have to look into it more. But since it's anyway not a use case that should be done, since as I said it's bad for performance and physical stability, not sure if it's worth investing time into fixing this one.

Later Edit:

To explain more on this, it's as if you are teleporting the second rigidbody every frame instead of letting the physics server update it. Which is not necessarily bad, for if you want to teleport the body every frame, either use kinematic body for that or static body. If you don't, then use rigidbody with impulse.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants