- Home /
How to rotate an object to "sit" on a sphere
I have a sphere (the globe) and am pinning airplanes to this the globe using longitude and latitude coordinates gathered form an API, OpenSky.
The planes are pinning to the globe in the correct position but are all facing towards it. This would be ok if the bottom of the plane faced the globe as it would appear to be "sitting" on it
private void CreateAndPinToGlobe(float latitude, float longitude) { float latInRadians = latitude * Mathf.Deg2Rad; float longInRadians = longitude * Mathf.Deg2Rad; float xPos = (radius) * Mathf.Cos(latInRadians) * Mathf.Cos(longInRadians); float zPos = (radius) * Mathf.Cos(latInRadians) * Mathf.Sin(longInRadians); float yPos = (radius) * Mathf.Sin(latInRadians); Vector3 position = new Vector3(xPos, yPos, zPos); Vector3 direction = (globe.transform.position - position).normalized; Quaternion lookRotation = Quaternion.LookRotation(direction); airplane.transform.localScale = new Vector3(4f, 4f, 4f); airplane.SetActive(true); Instantiate(airplane, position, lookRotation); } }
.
Answer by misher · Jul 26, 2019 at 09:40 AM
You still need the plane facing direction, as an option you could find it having 2 points on the route of the plane, for example, where it was some time ago and where it is now, this is approssimative solution tho. You can also get the surface normal of the sphere below the plane, this gives you the plane to "sit" on sphere, but it will still face in a random direction around that point, so it might be a wring representation if you want to simulate plane movement.
Your answer
Follow this Question
Related Questions
How can i rotate my rocket with out it zooming of in different directions 0 Answers
Rotate camera only in 2 directions based on player touch 1 Answer
player rotate to camera direction but not moving in it's direction 0 Answers
Rotate around sphere using Quaternions with full radius 1 Answer
How do i get the Raycast rotation? 1 Answer