- Home /
Problems with an object rotating a sphere surface (Quaternions and LookAt)
I have a sphere on position (0,1.5,0) with a .5 radius (diameter = 1), I have a pyramid too with this script that takes the transform of the sphere for LookAt and the lat/long to coordinate the pyramid:
public class LatLong : MonoBehaviour
{
[SerializeField]
public float longitude;
[SerializeField]
public float latitude;
[SerializeField]
private Transform Earth;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = Quaternion.AngleAxis(longitude, -Vector3.up) * Quaternion.AngleAxis(latitude, -Vector3.right) * new Vector3(0, 0, .5f);
transform.LookAt(Earth.transform.position);
}
}
Everything works fine if I comment " transform.LookAt(Earth.transform.position);", I can change the latitude and longitude and my pyramid works like a champ but the pyramid tip don't change soo i want to use transform.LookAt to solve the problem, but when I uncomment "( transform.LookAt(Earth.transform.position);", the pivot of my pyramid change to (0,0,.5) and turn around the origin (0,0,0) so the pyramid change it's position too and the lat, long.
¿There is something wrong between use Quaternions and LookAt?
Thank you very much. : )
Your answer
Follow this Question
Related Questions
LookAt whilst traversing a sphere 2 Answers
2D look at 1 Answer
Lerp rotation relative to sphere 0 Answers
how to limit axis of rotation when looking to a target 1 Answer