Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.55k stars 120 forks source link

Add optional `rotation_offset` to FixedJoint #507

Open RJ opened 2 months ago

RJ commented 2 months ago

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

https://github.com/user-attachments/assets/0e206743-37c5-4453-b4cc-d9cf3339d114

New output with rotation offset applied

https://github.com/user-attachments/assets/5429ceb8-196b-486c-9adf-812c10f894eb

Caveat

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


Changelog

RJ commented 2 months ago

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

https://github.com/user-attachments/assets/c7b834e0-124c-4805-9a38-72223b3a5660