dimforge / rapier.js

Official JavaScript bindings for the Rapier physics engine.
https://rapier.rs
Apache License 2.0
435 stars 58 forks source link

Is it not possible to make a vehicle using revolute joints for the wheels? #196

Closed torkeldanielsson closed 1 year ago

torkeldanielsson commented 1 year ago

I am trying to create a vehicle and my approach is to use a RigidBody for each of:

I then set up revolute joints for the wheels and the steering. When I apply steering using set_motor_position and throttle/brake using set_motor_velicity I get the expected result if I let things hover in the air with no ground contact: https://user-images.githubusercontent.com/634877/210060114-e120e304-5c10-478d-8323-8b1f28a0a2fe.mp4

But, when I drop it to the ground it starts behaving super weird, glitching and twitching and rolling back and forth: https://user-images.githubusercontent.com/634877/210060212-96a725d8-5b99-49db-b7b1-1ff7ea4c2012.mp4 (Sorry for shakiness from filming screen, hopefully the glitches are obvious... And this is after reducing the weight of things drastically - at higher weights it was really nuts!)

Now, my main question here is to check that I am not totally on a wrong track with this? It seems logical to be able to use revolute joints like this. But even without steering, just four wheels, if I set ridiculous amount for max_motor_force and set_motor_velocity to zero this thing will still creep slowly and randomly back and forth.... That to me seems like I have some major misunderstanding what revolute joints can be used for? Are they only for "show" and can't handle contact with ground?

Then I also have a minor separate question - how am I to retrieve a joint so I can set speed for it during the update loop, given a MultibodyJointHandle? I came up with this code:

let motor = self
    .multibody_joint_set
    .get_mut(self.wheel_front_left_motor)
    .unwrap();

let joint = &mut motor.0.link_mut(3).unwrap().joint;

joint
    .data
    .as_revolute_mut()
    .unwrap()
    .set_motor_position(steering_angle, 500.0, 50.0);

The call there to link_mut(3)... that surely is not correct 😅

torkeldanielsson commented 1 year ago

Aaaand, I posted to .js. Crap, sorry. Closing and opening in correct place... 😓