Search Unity

How to freewheel using wheel joint 2D

Discussion in 'Physics' started by cratica, Sep 17, 2019.

  1. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    Hello all. I am trying to create a side scrolling car game and have purchased the 2d racing game as well as watched many tutorials/videos that all show how to setup a car. They are all similar but none of them address the issue I am having. Once you press the key and apply power to the driven wheels, the car behaves like an old wind up car toy that has energy until the spring is unwound.

    For example, if you give the car some gas then let off, it will continue climbing up a steep hill using driven power until the car slows down (which right now is a Lerp). The problem with this is 1) its not natural and it doesn't feel right 2) it keeps the car from free rolling downhill.

    It should disengage the "motor" and freewheel just like the front wheel when you let off the throttle with only the physics....gravity/inertia/drag controlling how far and fast the car will go/slow down.

    I hope I have explained this correctly. In looking into this issue, Reading through the reference material I saw how one of Unity's other 2d functions allowed the motor to be disengaged if speed is set to 0. Unfortunately, this just locks up the wheel if I try that with wheel joint 2D.

    Anyone have any thoughts on how to fix this non-free wheeling motor issue?

    Thx
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Turning off the motor is done by, well, turning off the motor with WheelJoint2D.useMotor which is the same as the HingeJoint2D and SliderJoint2D.

    Specifically, these are obviously not "real" motors. They are constraints which try to ensure the rotation speed maintains the speed you set, so a motor speed of zero is where the motor is on and is trying to stop the wheel or as you put it "locks the wheel".
     
    cratica likes this.
  3. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    Thank you very much. I was able to resolve the issue by moving some updates around and adding that command if no input. Works exactly as I want it to. Again thank you for replying!