Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Wheel Joint 2D, wheels moving strangely when in speed

Discussion in '2D' started by aqsanadeem82, Jan 14, 2021.

  1. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    I want to move my car in a hill climb game but when the car moves fast the wheels start to bounce. I am moving the wheels through arrow keys.
    Here is the visual representation of the behaviour of wheels: Video
    This is my Inspector for wheel joint :

    Code (CSharp):
    1.  
    2.     public Rigidbody2D carController;
    3.     public Rigidbody2D backTire;
    4.     public Rigidbody2D frontTire;
    5.     public float speed;
    6.     public float carTorque = 10;
    7.     public float fuel = 1;
    8.     public float fuelConsumption = 0.1f;
    9.  
    10.     public Image fuelImage;
    11.     private float movement;
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         //To get inputs from keyboard
    17.         movement = Input.GetAxis("Horizontal");
    18.         fuelImage.fillAmount = fuel;
    19.     }
    20.     private void FixedUpdate()
    21.     {
    22.         //&& -movement * speed * Time.fixedDeltaTime<1.8 && -movement * speed * Time.fixedDeltaTime>-1.8
    23.         if (fuel > 0)
    24.         {
    25.             //Rotate the tires based on inputs
    26.             backTire.AddTorque(-movement * speed * Time.fixedDeltaTime);
    27.             frontTire.AddTorque(-movement * speed * Time.fixedDeltaTime);
    28.          
    29.             carController.AddTorque(-movement * carTorque * Time.fixedDeltaTime);
    30.             print(movement);
    31.         }
    32.         fuel -= fuelConsumption * Mathf.Abs(movement) * Time.fixedDeltaTime;
    33.     }
     
  2. KaiFGames

    KaiFGames

    Joined:
    Dec 11, 2022
    Posts:
    1
    Hi,
    I had a simular problem, and I found out the problem isn´t in the code, but in the wheel joint 2D. You just have to set the damping ratio to zero and the frequency as high as you need. It´s still "wobbling", but so tiny you almost can´t even see. Hope I could help.