Car tutorial crashed Unity

Hello All,

Playing with the car tutorial
and got an error on the advance physics lessons and crashed Unity.

The folowing are the error reports.

  1. “System.NullReferenceException:Object reference not set to an instance of an object PlayerCar: FixedUpdate() (at Assets[A] Car Control/5 More Physics/PlayerCar.js:37”

  2. "System.NullReferenceException
    UnityEngine.Transform:set_localRotation(Quaternion value)
    UnityEngine.Transform:set_localEulerAngles (Vector3 value)
    PlayerCar:FixedUpdate() (at Assets/[A] Car Control/5 More Physics/PlayerCar.js:37

Don’t quite understand the errors yet. Is there something wrong the scripts.

Pasting that script here

Thanks,
Ray

// These transforms need to be connected in the inspector,
// so the script can identify the wheels.
var frontLeftWheel : Transform;
var frontRightWheel : Transform;
var backLeftWheel : Transform;
var backRightWheel : Transform;

// Speed is a multiplier of how much force we add to the wheels every frame
var speed = 150;
// The maximum steering angle of the wheels
var maxSteerAngle = 30;

// This is used to track if
private var hasBackWheelContact = false;

// Tweak the center of mass.
// - Low center of mass a bit towards the front
// - model a long long and not very high car
rigidbody.centerOfMass = Vector3 (0, 0, 0);
rigidbody.inertiaTensorRotation = Quaternion.identity;
rigidbody.inertiaTensor = Vector3 (1, 1, 2) * rigidbody.mass;

function FixedUpdate () {
var motorForce = speed * Input.GetAxis (“Vertical”);

// Do the wheels touch the ground?
// Apply force along the z axis of the object
if (hasBackWheelContact) {
rigidbody.AddRelativeForce (0, 0, motorForce);
}

// The horizontal is in the range [-1 … 1]
// The maximum steer
var rotation = Input.GetAxis (“Horizontal”) * maxSteerAngle;

// Set the rotation around the y-axis of both wheels
frontLeftWheel.localEulerAngles = Vector3 (0, rotation, 0);
frontRightWheel.localEulerAngles = Vector3 (0, rotation, 0);

// This tracks if the back wheels are grounded.
// Every frame we reset the variable,
// OnCollisionStay will then enable the variable if the wheel is grounded.
hasBackWheelContact = false;
}

// This is called every frame if the car collides with something.
// This is used to calculate if the wheels touch the ground.
function OnCollisionStay (collision : Collision)
{
for (var p : ContactPoint in collision.contacts)
{
// Enable hasBackWheelContact if we are touching the ground
if (p.thisCollider.transform == backLeftWheel)
hasBackWheelContact = true;
if (p.thisCollider.transform == backRightWheel)
hasBackWheelContact = true;
}
}

My Bad

Forgot to assign a target to transform :smile:

Ray