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

‘motorTorque’ is not a member of ‘System.Type’.

Discussion in 'Scripting' started by Dark-Andy, May 10, 2011.

  1. Dark-Andy

    Dark-Andy

    Joined:
    May 10, 2011
    Posts:
    15
    Hi, I'm trying to make my first car-game work.

    Code (csharp):
    1. var leftWheel = WheelCollider;
    2. var rightwheel = WheelCollider;
    3. var maxtorque = 260.0;
    4.  
    5. function Start () {
    6.     rigidbody.centerOfMass.y = 0;
    7. }
    8.  
    9. function FixedUpdate () {
    10.     leftWheel.motorTorque  = maxtorque * Input.GetAxis("Vertical");
    11.     rightwheel.motorTorque = maxtorque * Input.GetAxis("Vertical");
    12.  
    13.     leftWheel.steerAngle = 10 * Input.GetAxis("Horizontal");
    14.     rightwheel.steerAngle = 10 * Input.GetAxis("Horizontal");
    15. }
    This script leads to an error I can't understand.

    What went wrong here and how can I fix it?

    Thanks - dark andy
     
  2. Marrrk

    Marrrk

    Joined:
    Mar 21, 2011
    Posts:
    1,032
    This here will not work as you expect:
    Code (csharp):
    1. var leftWheel = WheelCollider;
    WheelCollider is a Type and not an instance of the type WheelCollider.

    Write it like this to declare a variable which can take an instance of type WheelCollider:
    Code (csharp):
    1. var leftWheel : WheelCollider
    Do this too for your rightWheel.
     
  3. Dark-Andy

    Dark-Andy

    Joined:
    May 10, 2011
    Posts:
    15
    Oh, thank you.
    Sometimes the solution is so close and yet so far...
    It works!