rotation/euler angles/quaternion

Hello All,

I got a console x again, System.NullReferenceException. (sorry still learning Unity).
Anyway the error is
“UnityEngine.Transform:set_localRotation(Quaternion value)”.
“UnityEngine.Transform:set_EulerAngles(Vector3 value)”.

And a reference to my script;(Modified the AICar Script)

  1. UpdateWithTargetPosition(Vector3 target)
  2. FixedUpdate()

Script from the UpdateTargetPosition
function UpdateWithTargetPosition (target : Vector3)
{
//calculate target position relative to the target(waypoint)
//coordinate system + x value = target to the right
//+z target is in front

relativeTarget = transform.InverseTransformPoint(target);

//calculate target angle to point towards the target

targetAngle = Mathf.Atan2(relativeTarget.x, relativeTarget.z);

//Atan returns angle in radians, convert to degrees

targetAngle *= Mathf.Rad2Deg;

//Maximum rotation angle

targetAngle = Mathf.Clamp (targetAngle, -steerMaxAngle, steerMaxAngle);

//Apply movement, Muncher is a private var

Muncher.localEulerAngles = Vector3 (0,targetAngle,0);

And the FixedUpdate.
function FixedUpdate()
{
//calculate position should be going towards target;

targetPosition = activeWayPoint.CalculateTargetPosition (transform.position);

//apply force, steer object;

UpdateWithTargetPosition (targetPosition);
}//end FixedUpdate

My object moves but it’s going the other way and my arrow keys now is all messed up. Up/Down became sideways and left/right became forward/reverse.

Appreciate any help I can get.
Thanks,
Ray

PS. I also lost my sight(crosshair) again. :frowning:

You get System.NullReferenceException when you’ve forgot to assign a value to a variable before using it. From what I can see from the stack trace you wrote, it seems to be the Muncher variable that is not set.

Btw. the error message tells you what line it failed at as well as the file name. You can even double click it to open it and it will select the line the error happened in for you.

Muncher var is declared as private and set, double clikcking it help me figured out what’s missing. I forgot to set my transform target in the inspector field.

Thanks,
Ray