I have a sphere with a rigidbody and no gravity. It controls the camera (or it’s supposed to) but unity sends me this error message :
;
transform.position assign attempt for ‘Sphere’ is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform:set_position(Vector3)\
;
my code has worked before, but for some reason, unity refuses to admit that the sphere has a transform.position…
;
Here is my code:
// Start is called before the first frame update
void Start()
{
[Range(0.1f, 25f)]
public float speed;
[Range(0.1f, 1f)]
public float sensitivity;
bool up;
bool down;
bool left;
bool right;
bool forward;
bool backward;
float speedChange;
float sensChange;
}
// Update is called once per frame
void Update()
{
// getting inputs
up = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
down = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);
left = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
right = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
forward = Input.GetKey(KeyCode.E) || (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.UpArrow));
backward = Input.GetKey(KeyCode.Q) || (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.DownArrow));
speedChange = Input.mouseScrollDelta.y / Mathf.Abs(Input.mouseScrollDelta.y); // only {-1 ; 0 ; 1}
if(Input.mouseScrollDelta.y != 0 && Input.GetKey(KeyCode.LeftControl))
{
sensChange = Input.mouseScrollDelta.y / Mathf.Abs(Input.mouseScrollDelta.y);
}
;
// applying inputs /////////////////////////THIS IS WHERE THE ERRORS ARE///////////////
if (up) transform.position += transform.up * speed * Time.deltaTime;
if (down) transform.position += transform.up * speed * -1 * Time.deltaTime;
if (left) transform.position += transform.right * speed * -1 * Time.deltaTime;
if (right) transform.position += transform.right * speed * Time.deltaTime;
///////////////////////////////////////END OF ERRORS///////////////////////////
speed += sensitivity * speedChange;
sensitivity += sensChange * .1f;
}
Excuse the format, I don’t really know how to work with this site yet