Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Front of the car is lifting into the air

Discussion in 'Editor & General Support' started by tomsk, Sep 2, 2014.

  1. tomsk

    tomsk

    Joined:
    Jan 25, 2014
    Posts:
    7
    Hello, i have a car bith basic movement script, i just followed this tutorial:

    and I did everything exactly like in the video and yet the front of my car is lifting into the air. I dont know why.

    There is animation: https://imgflip.com/gif/bcccu

    There is my script:

    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.    
    4.    
    5.    
    6.     public class Ovladanie : MonoBehaviour {
    7.        
    8.         public WheelCollider WPL;
    9.         public WheelCollider WPP;
    10.         public WheelCollider WZP;
    11.         public WheelCollider WZL;
    12.        
    13.         int rychlost = 50;
    14.    
    15.         // Use this for initialization
    16.         void Start () {
    17.             Vector3 centerOfMass = rigidbody.centerOfMass;
    18.             centerOfMass.y = -0.9f;
    19.         }
    20.        
    21.         // Update is called once per frame
    22.         void FixedUpdate () {
    23.             WZL.motorTorque = rychlost * Input.GetAxis("Vertical");
    24.             WZP.motorTorque = rychlost * Input.GetAxis("Vertical");
    25.            
    26.             WPL.steerAngle = 10 * Input.GetAxis("Horizontal");
    27.             WPP.steerAngle = 10 * Input.GetAxis("Horizontal");
    28.         }
    29.     }
    Sorry for my english

    Thank you for any help
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    One thing i can tell is that you do not apply the value of -0.9f to the actual rigidbody.centerOfMass.
    In C#, Vector3 is a data-type, not a reference type, which means if you 'get' the centerOfMass and adjust it the way you do it, you also need to re-assign it to the original as it's currently just a copie.

    Add this line below the ones in the Start-Function, maybe that's all that is needed:

    Code (csharp):
    1.  
    2. rigidbody.centerOfMass = centerOfMass;
    3.  
     
    Last edited: Sep 2, 2014
  3. tomsk

    tomsk

    Joined:
    Jan 25, 2014
    Posts:
    7
    interesting, i made everything from scratch and at the moment car is no lifting anymore at speed 50, but at speed 80+ its starting, thank you :D i think its no problem, but at the moment my car is flipping when i turn :/ and another interesting thing is that in video its working correctly...

    At the moment my start function looks like:
    Code (CSharp):
    1.     void Start () {
    2.         Vector3 centerOfMass = rigidbody.centerOfMass;
    3.         centerOfMass.y = -0.9f;
    4.         rigidbody.centerOfMass = centerOfMass;
    5.     }
     
    Last edited: Sep 4, 2014
  4. tomsk

    tomsk

    Joined:
    Jan 25, 2014
    Posts:
    7
    Any help with flipping? :(