rapier
rapier copied to clipboard
set_motor_velocity
I cannot change the parameters of a motor after it has been created. I used set_motor_velocity. The console output shows that the data in the motor has changed, but the behavior of the associated colliders does not change. Perhaps it is worth adding work with set_motor_velocity to the joint example?
I found a great project using motor velocity: https://github.com/RichTeaMan/combine-derby.git
For anyone who stumbles on this one in the future, I can confirm that the method set_motor_velocity()
changes the value of the target_vel
property on JointMotor
, but that has no impact on the physics pipeline. I'm not sure why this is the case (possibly because the pipeline does not use the reference to ImpulseJoint, using the GenericJoint instead?), but I can recommend the following simple approach to simulating a dynamically changing motor:
for (
_joint_handle,
impulse_joint
) in self.impulse_joint_set.iter_mut() {
// impulse_joint.data.set_motor_velocity(
// JointAxis::X,
// TARGET_VELOCITY * self.motor_direction,
// DAMPING_FACTOR,
// );
self.rigid_body_set.get_mut(impulse_joint.body1).unwrap().apply_torque_impulse(
self.motor_direction * MOTOR_MAX_TORQUE,
true,
);
self.rigid_body_set.get_mut(impulse_joint.body2).unwrap().apply_torque_impulse(
-self.motor_direction * MOTOR_MAX_TORQUE,
true,
);
}
As you can see, I commented out the "broken" approach using set_motor_velocity()
. But directly applying impulse (torque in my case) works.
@taslater In your call to set_motor_velocity
, you specified the axis JointAxis::X
. This is the axis for the translational movement of the motor (which won’t have any effect if you are doing that on joints locking translations (like revolute or spherical joints). Since you are applying torques instead, I assume you wanted to motorize the angular axis. So you should use the JointAxis::AngX
axis instead. Please let me know if that worked.
Considering how old the original issue is, I suppose KnstAnt was using an older version of rapier that had issue with motor implementations (on previous iterations of rapier’s solver).
Wonderful! You are absolutely right. Thank you. I consider this issue resolved.
@taslater Perfect, glad to hear that worked. @KnstAnt I’m closing this issue since it’s pretty old and it should work properly now. Don’t hesitate to open a new one if you are still having issues.