- Home /
How to apply frictional Torque
Hi
So my goal is ultimately to simulate a PID controlled wheel for a ball balancing on top of it, for those who know something about control systems. Nevertheless for the beginning, I want to make a wheel controlled by a human, in this case me, steering the direction of rotation of the wheel with the left and right arrow keys.
So I imported the wheel from a CAD model as an .obj file and made the ball in Unity. I implemented the controls for the wheel like this:
I added a mesh collider to the wheel and a sphere collider to the ball. I can rotate the wheel, but it does not affect the behavior of the ball. I tried applying physics materials and added maximum friction. Even trying the same thing with two cylinders from Unity does not work.
So, how can I achieve the frictional torque from the wheel? Side note: The custom wheel is not a rigid body because, it would delete the mesh collider and add a very primitive collider to it.
Thank you in advance!
Answer by Shrimpey · Mar 30, 2020 at 09:05 AM
Do mind that transform.Rotate does rotate the object, but does not affect physics engine itself. No torque is added this way to the rigidbody. You need to have rigidbody and then use rb.AddTorque to make the physics engine rotate the object.
Answer by matthrubii · Mar 30, 2020 at 10:05 AM
@Shrimpey Thank you for answering! Ok, I will keep this in mind. I tried to make a rigid body out of my CAD wheel model, and turned out that the mesh collider would turn to a primitive collider like a cylinder and "lose" the actual geometry for colliding with the ball. How can I apply Rigid Body and keep the complex collider as it is ? If this doesn't work would I have to make it with a normal cylinder geometry?
I don't quite understand, when you have a gameobject, you can just add "$$anonymous$$esh Collider" component and choose your complex shape there. So your GO should have mesh filter, mesh renderer, Rigidbody and $$anonymous$$esh collider. On top of that, I think that for your purpose you should have simple, cylinder collider, complex mesh colliders can be buggy, especially as the only thing you need it for is cylinder like rotation.
Nice thank you! I managed to apply torque to the wheel and it really works with the friction and so on... Nevertheless I'm still wondering why my mesh collider disappears, as I add a rigid body to the wheel and the "colliding zone" is only in a form of a cylinder. So maybe I have to mention that the wheel is imported by CAD model and it kind of split up into a mesh, a prefab and a material in unity. As I add the wheel to the scene I have a children and a parent object. And I don't know exactly to which part I should apply all those things like mesh renderer etc... If this work I would try this because this looks more realistic than a normal cylinder form.
Oh, I have not worked with CAD models, you'll need to do your own research on that, but my guess is that the way you made it in CAD was with a few separate parts (meshes) and hence Unity is importing it that way. You should look into your CAD software and see if it is possible to merge all the parts and export as one mesh. You can also look at the imported object properties in Unity, maybe there will be some useful import options there for you to check.
Your answer
![](https://koobas.hobune.stream/wayback/20220612225825im_/https://answers.unity.com/themes/thub/images/avi.jpg)