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â?
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.
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?
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.