Drive wheel with rotation, not torque

Hi community, I would like to create a cart which has separate step-motors for each wheel and I cannot make it move. I would like to send rotation signals to motors (e.g. rotate clockwise for 180 degrees) and achieve cart movement by that rather than torque. I experimented with Physic Material and friction and had no luck: no traction between wheels and ground.

Any suggestion how to get to result?

That is how I spin my wheels:

public Rigidbody WheelLeft;

var rotationLeft = Quaternion.Euler(0, stepLeft, 0); //I did wheels out of cylinders.
WheelLeft.transform.rotation = WheelLeft.transform.rotation * rotationLeft;

PS
As I modeled my wheels out of cylinders, I was completely unsuccessful to add wheel collider to them (wrong rotation axis).

PPS
It appears that just adding Wheel Collider doesn’t work anymore as pointed here. [edit: it works]

Unfortunately, that’s not how the physics system works. By manipulating the rotation of the transform, you’re effectively telling the physics engine: “i know the wheel was rotated like this, but now I teleport it into this new rotation”. There is no way of knowing for physx, that you meant by that line of code that there should be a rotation with an angular velocity there.

You can go down different roads now: Use a wheel collider and build a controller around it that lets you set a rotation value and that uses feedback control, to reach that rotation

Use joints to model the wheels… I don’t know how well this works, but I expect it to be more painful than wheel controllers and it also involves developing a small feedback controller (don’t worry, sounds harder than it is)

On your PPS: Where in that documentation article does it say that it just “doesn’t work anymore”?

1 Like

A good first approach would be using WheelCollider as wheels and rotate them using WheelCollider.steerAngle. Rotating the transform of a WheelCollider don’t have any effect, use steerAngle instead.

Using cylinders as wheels won’t work because these are mesh colliders with hard edges physics-wise. Even though rotating them in the correct way (making them independent rigidbodies and attaching them to the main vehicle with a joint, then rotating them using the joint’s API) the situation will be detected as a collision by the physics engine, and will be resolved as such.

2 Likes

Edy, not sure how I can rotate a Wheel Collider on it’s X axis using steerAngle. My goal is to avoid using torque on wheels or force on body. I want to set up a way to control cart using rotation of a wheel. Could you please clarify?

It was my impression as I did not connect Wheel Colliders properly to rigid body. So it works.

Thank you for suggestions.

Oh, sorry, I meant rotating as for steering. Using WheelColliders you have to use motorTorque and brakeTorque on them. I don’t think there’s a way to get proper results by rotating colliders.

Here is an update. I used following construct:
Body <- Joint-axis -> Joint <- Join-fixed -> Rubber

Where ‘Joint-axis’ is Configurable Joint with everything locked but one axis; ‘Joint-fixed’ - Configurable Joint where everything is fixed.

I applied rotation to ‘Driver’ object, I used very same code and it worked. But other problem has manifested itself. There is some weird behavior when I try to turn, it feels that there is some spring.

I think video will help much better in this case.

PS
Body rotates as I forgot to reduce size of it’s collider and it was touching ground. I turned it off and now body doesn’t have any rotation. Though behavior remains. Plus I noticed that I can break Configurable Joint if set body mass too low.