Search Unity

AddRelativeTorque doesn't propel an object fast enough

Discussion in 'Physics' started by BongMcPuffin, Nov 14, 2017.

  1. BongMcPuffin

    BongMcPuffin

    Joined:
    Oct 16, 2017
    Posts:
    26
    So I'm trying different ways to propel a tire across the ground, and I've been running into a few quirks and issues with the different methods I've been exploring.

    The first method I used was to AddForce and this seems to work at slow speeds just fine, but anything higher than 20 units in my script and it will start to wobble after some distance, and it isn't realistic to how tires are actually powered. The good thing about AddForce is that it responds as you'd expect if you cranked the dial way up and hit the forward button, where the tire goes flying or you can crank it down and it just crawls along. It was also fairly easy to hook it up to an orbit camera and use the camera to dictate direction of the applied force to steer the tire. The following is a video showing the wobble being introduced by gravity and is why I'm searching for a different approach to powering the tire while on flat ground.



    On the other hand, AddRelativeTorque is my second attempt at powering this tire, but it seems to have an odd effect in that no matter how high I turn the dial, it just rolls forward at a fairly slow pace, and no matter what mass/traction I give both the tire and the ground, nothing changes in terms of speed unless I make the tire super heavy then it slows it down a bit, but making it super light doesn't speed it up past a certain point.

    I don't understand why adding more torque and thus (supposedly) turning the tire faster doesn't result in more speed though. The following is a video showing that, and I have the speed cranked waaaay up to 500,000 units.



     
  2. BongMcPuffin

    BongMcPuffin

    Joined:
    Oct 16, 2017
    Posts:
    26
    Ok so I've done some digging and I found the culprit is that the maxAngularVelocity is apparently being clamped somewhere.

    The problem with this is that there isn't anywhere that I can see to change the maxAngularVelocity. It apparently used to be in the Physics manager, but has since been removed for some reason. Apparently you need to write a script for this now, but I'm having a hard time nailing down where to actually put the code. I assume you put it in your control script for the attached object, but the documentation is lacking in any examples of how to do this exactly.

    https://docs.unity3d.com/ScriptReference/Rigidbody-maxAngularVelocity.html

    Code (CSharp):
    1. public float maxAngularVelocity;
    Thats all there is in there, which I added to my code, and it shows up in the inspector and I can change the value but it doesn't look like its hooked up to anything, because no matter what I number I set in there it doesn't change anything when I run the game.

    This seems like it would be a fairly common thing to come up, where people would need to adjust the speed of a torqued object... I just can't understand why a simple and easy solution to this was removed from the physics manager and made into this convoluted, unintuitive way of doing things... at least it feels convoluted and unintuitive to me as a noob.

    EDIT: I spoke too soon, I figured out how to unclamp the value.

    Code (CSharp):
    1. GetComponent<Rigidbody>().maxAngularVelocity = maxAngularVelocity;
    But I'm running into even more problems now... with the increased speed, the tire goes absolutely crazy.



    In the above video I'm not turning the tire at all... it just does that while applying torque. It ALWAYS seems to pitch to the left as well. Not sure what to make of that.

    I'm starting to feel like this game and Unity are the two faces of a vice and my sanity is being squeezed in the middle.

    2ND EDIT: Clamping the X and Y rotation keeps the tire upright, but it bounces across the ground as I apply the torque.

    Nothing works like its supposed to.

    Starting to feel hopeless and burnt out.

    Guess I'll try again tomorrow.
     
    Last edited: Nov 15, 2017
  3. BongMcPuffin

    BongMcPuffin

    Joined:
    Oct 16, 2017
    Posts:
    26
    As I was sifting through the documentation, I came across AddForceAtPosition, which sounds promising if it can be pulsed on and off.

    This makes sense to me, because my initial inspiration for this game came from watching someone play with a hoop-and-stick. They are simply whacking the outer surface of the hoop, giving it both a torque and a small force, which is what AddForceAtPosition supposedly does, and to keep the hoop rolling along you have to keep giving it a whack every once in a while, and the more you hit it, the more stable the hoop and the faster it will go. Stop hitting the hoop and it will eventually run out of speed and fall over, which is like pulsing AddForceAtPosition tapping the forward key over and over.



    AddForce and AddRelativeTorque were both being driven continuously in my script, instead of being pulsed, which was too "pushy" and not realistic to how a free-standing hoop would be propelled, because AddForce was basically like if the tire was caught in a perfectly horizontal hurricane force wind and was being pushed along in a straight line regardless of its orientation. AddRelativeTorque was like if I hooked a wheel up to a dremel and I touched that spinning wheel to the ground, which would work fine as a propulsion method for very slow speeds, but once it starts to slip it'll bounce and go crazy if I don't stop applying torque (turn the dremel off), and this also has the added side-effect of essentially gyroscopically locking the tire while the torque was being applied.

    I'll try hooking this all up tomorrow, but for now I'm fried. I'm still not sure how this is going to be able to be steered through my orbit camera though... so thats still a headache I'll have to deal with.
     
    Last edited: Nov 15, 2017