So i was translating my c# Click to move script into javascript, everything was going find until i got to the very end. I keep getting this error : NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
So after i assign my Character Controller in the inspector i still get this error, what could i have done wrong?
Code -
var speed:int; // Determines how quickly object moves towards position
var controller : CharacterController;
private var position:Vector3;
function start ()
{
position = transform.position; // stops from moving directly to origin at start
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
//locates position
locatePosition();
}
//moves to position
moveToPosition();
}
function locatePosition ()
{
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast (ray, hit, 1000));
{
position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
Debug.Log(position);
}
}
function moveToPosition ()
{
if(Vector3.Distance(transform.position, position)>1)
{
var newRotation = Quaternion.LookRotation(position - transform.position);
newRotation.x = 0f;
newRotation.z = 0f;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
controller.SimpleMove(transform.foward * speed); // problem
}
}
I’m pretty sure the problem has to do with the line “controller.SimpleMove(transform.foward * speed); // problem” because when i comment it out the game runs fine, i just don’t know how to fix it.