Here is a little background on how my game objects are set up, and how the rotations and firing bullets work. I am working on this game in Unity.
I have two game objects that orbit a sphere (for simplicity lets say the player is a space ship and the enemy is a UFO). The UFO shoots at the ship in a spherical manner around the surface of the sphere (my intention at least).
The ship and UFO both have a parent game object that is located at the center of the sphere, and each are moved back on the z-axis by 10 units. All of the movement rotations are applied to the parent pivot points which causes the two objects to orbit freely in any direction as the pivot points rotate.
In this previous question I received some help to get my bullets to fire from the UFO towards the ship. The solution provided works great, the UFO always fires bullets towards the ship as the ship flies around. Once both objects move to opposite side of the sphere (past 180 degrees from the original starting point) the direction to fire the bullet seems mirrored. As the ship flies around the, the bullets fly in a mirrored direction.
Here is how I am rotating the bullets (note: I use the same pivot point technique as stated above for the bullets as well):
When shooting a bullet I first I generate a direction vector like so:
var ufoSpoke = ufo.transform.position - Vector3.zero; var shipSpoke = ship.transform.position - Vector3.zero; var pointOut = Quaternion.LookRotation(ufoSpoke, -shipSpoke); var pointOnShortestArc = pointOut * Quaternion.Euler(90f, 0, 0); var direction = (pointOnShortestArc * Vector3.right).normalized * 50f;
Now within the update method for the bullet pivot point, I rotate the pivot object in this direction:
transform.Rotate(direction.y * Time.deltaTime, -direction.x * Time.deltaTime, 0f);
This all is working great, until the ship and UFO start moving around the sphere. Eventually the calculated bullet direction goes from just slightly off, to mirrored once on the backside of the sphere... If I fly the ship back to the original starting point, the bullet direction comes back properly.
Not quite sure what the issue seems to be, and I've admittedly been looking at this far too long haha. Thanks in advance for any help on this!