The question is answered, right answer was accepted
Rotating transform around axis specified by another object in world
I am trying to make a game which takes place mostly on an ocean. I'm not going into very high detail so I didn't make the water physically realistic. I am trying to rotate the model of my boat around an axis defined by a "Wave Director" transform. What is happening though is that no matter which way my ship points it always rotates the same. The code I am using is shown below.
ShipBody.Rotate(WaveDirector.right waveStrength (1 - Mathf.PingPong(Time.time * 2, 2)));
The code is supposed to "Ping Pong" rotate the ship about 90 degrees of the direction of the waves as defined by the "WaveDirectors" Forward direction to simulate the bobbing you might get from actual waves. The code is currently just place into the update function and I expected that to cause an updated direction, but I expect the problem comes from the fact that I need to compare the boats forward direction to the wave directors right, but dont know how to do that.
Any help would be deeply appreciated.
Answer by DocLamb · Feb 16, 2017 at 02:28 PM
Not positive if this is the best way but i seem to have solved my problem with a non-elegant solution
ShipBody.Rotate((WaveDirector.right-(transform.right+transform.up+transform.forward)) * waveStrength * (1 - Mathf.PingPong(Time.time * 2, 2)));