So I'm rotating an object around a sphere using the below code:
transform.LookAt(target2);
The problem is that I don't want it to rotate along the Z axis, only the X and Y axis. How would I do this?
So I'm rotating an object around a sphere using the below code:
transform.LookAt(target2);
The problem is that I don't want it to rotate along the Z axis, only the X and Y axis. How would I do this?
What you want it to do is keep the position of the target's z axis but only transform the x and y axis, like below.
transform.LookAt(Vector3(transform.position.x, transform.position.y, target2.position.z));
Thank you for this response! Its been a huge help to me.
If it was me, I would use transform.RotateAround.
transform.RotateAround (objectToRotateAround.transform.position, new Vector3 (1, 1, 0), turnSpeed * Time.deltaTime)
I used this to rotate a tank turret where the “up/down” rotation is locked. It is basically pointing at the player which is an airplane.
gameObject.transform.LookAt(new Vector3 (GameObject.FindGameObjectWithTag(“Player”).transform.position.x, transform.position.y,GameObject.FindGameObjectWithTag(“Player”).transform.position.z));