Why won't my model rotate up on X axis?

Hi All,

I’m new to C# and Unity, and I’m struggling a bit with this code I am trying to create. Basically, the goal is to have a spaceship rotate in 3d space. Then, when the player triggers a speed script, the model moves in the direction the ship is facing. The speed works fine.

What isn’t working is the rotation. I can get it to rotate around its Y axis, and it rotates modestly around the Z axis as it rotates toward the targetPosition.

And, it will rotate down along the X (effectively tipping its nose down). But it won’t rotate up (tipping the nose up).


    void locatePosition()
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 1000))
            targetPosition = new Vector3(hit.point.x, hit.point.y, hit.point.z);

    void moveToPosition()
        //if destination is more than one unit away, activate movement actions
        if (Vector3.Distance(transform.position, targetPosition) > .25)
            Quaternion newRotation = Quaternion.LookRotation(targetPosition - transform.position);

            //lock rotation along axes
            //newRotation.x = 0f;
            //newRotation.z = 0f;
            //turn toward mouse click
            transform.rotation = Quaternion.Lerp(transform.rotation, newRotation, Time.deltaTime * rotateSpeed);
            Debug.Log("I'm rotating");

            //move character
            //BAD METHOD WRONG ACTION controller.SimpleMove(transform.forward * (Time.deltaTime * speed));
            Rb.AddRelativeForce(0,0, (Time.deltaTime * speed));
            Debug.Log("I'm Moving");

Is there something in my choice of functions that is preventing the upward rotation along X?

Any suggestions?


P.S. My camera rotation script uses effectively the same system, and it has the same problem.


Thanks all!