My code below is giving me a weird error. Rigidbody.velocity works just fine however rigidbody.position doesn’t. I recently started refractoring my code so I moved this into it’s own engine.cs class. It wasn’t giving my any errors before and now it is. I’m now getting a NullReferenceException. Does anyone know what the problem might be? Let me know if you need anymore information.
Vector3 movement = new Vector3 (moveHorizontal, moveVertical, 0.0f);
rigidbody.velocity = movement * (speed + speedAdder);
rigidbody.position = new Vector3 (
Mathf.Clamp (rigidbody.position.x, _ship._bounds.xMin + playerSize, _ship._bounds.xMax - playerSize),
Mathf.Clamp (rigidbody.position.y, _ship._bounds.zMin + playerSize, _ship._bounds.zMax - playerSize),
0.0f
);
rigidbody.rotation = Quaternion.Euler (rigidbody.velocity.y * tilt, 0.0f, 0.0f);