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 optional rotation_offset to FixedJoint #507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RJ
Copy link
Sponsor Contributor

@RJ RJ commented Sep 3, 2024

Objective

FixedJoints currently apply entity1's Rotation to entity2.

This change allows you set a fixed rotation offset to entity2's Rotation, relative to entity1.

Here's the output difference in the fixed_joint_2d.rs example, if you make this change:

-    commands.spawn(FixedJoint::new(anchor, object).with_local_anchor_1(Vector::X * 100.0));
+    commands.spawn(
+        FixedJoint::new(anchor, object)
+            .with_local_anchor_1(Vector::X * 100.0)
+            .with_rotation_offset(PI / 4.), // <--- NEW
+    );

Original output

example.without.rotation.offset.mov

New output with rotation offset applied

example.with.rotation.offset.of.quarter-pi.mov

Caveat

I've only visually confirmed this looks right in 2d.
Hopefully the 3d version of my get_rotation_difference is correct.


Changelog

  • Add FixedJoint::with_rotation_offset

@Jondolf Jondolf added C-Enhancement New feature or request A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Sep 4, 2024
@RJ
Copy link
Sponsor Contributor Author

RJ commented Sep 4, 2024

this change is so i can use a fixed joint to land on asteroids like this, maintaining the upright ship rotation:

landing-on-asteroid.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants