From 17d4641af6af30fbd43bcbda72ef6373609dd337 Mon Sep 17 00:00:00 2001 From: Zheng Luo Date: Tue, 9 Sep 2025 14:32:26 -0700 Subject: [PATCH] added the corresponding ball joint motor for 2d --- fyrox-impl/src/scene/dim2/joint.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fyrox-impl/src/scene/dim2/joint.rs b/fyrox-impl/src/scene/dim2/joint.rs index 8d089f4fc..0871052e0 100644 --- a/fyrox-impl/src/scene/dim2/joint.rs +++ b/fyrox-impl/src/scene/dim2/joint.rs @@ -475,6 +475,34 @@ impl Joint { self.set_motor_params(motor_params); Ok(()) } + /// Makes the [`BallJoint`] to restore its original orientation with motor torque. + /// + /// Acts as a flexible fixed joint that tolerates some angular movement and tries to restore the original orientation. + /// + /// For flexible fixed joints that tolerate some translational movement, consider using a [`PrismaticJoint`] and call [`Self::set_motor_target_position_as_prismatic`]. + /// + /// This function essentially calls [`Self::set_motor_target_angle_as_ball`] with a target angle of 0 radians. It is here to be symmetric with its 3D version, which is more useful in a 3D context. + /// + /// /// Call [`Self::disable_motor`] to stop the motor and remove the spring effect. + /// + /// # Arguments + /// * `stiffness` - Controls how fast the joint will try to restore its original orientation. + /// * `max_torque` - The maximum torque this motor can deliver. + /// * `damping` - Penalizes high angular velocities to avoid overshooting the original orientation. A higher damping value will result in a smoother transition to the original orientation. + /// # Errors + /// If the joint is not a [`BallJoint`], the function will do nothing and return an Err. + /// # Notice + /// The rigid bodies attached to the joint may fall asleep anytime regardless whether the motor is enabled or not. + /// + /// To avoid this behavior, call this function periodically or call [`RigidBody::set_can_sleep`] on the rigid bodies with "false". + pub fn set_motor_resistive_torque_as_ball( + &mut self, + stiffness: f32, + max_torque: f32, + damping: f32, + ) -> Result<(), String> { + self.set_motor_target_angle_as_ball(0.0, stiffness, max_torque, damping) + } /// Disables the motor of the joint assuming it is a [`BallJoint`] or [`PrismaticJoint`]. ///