Rotate object in 3d space along one axis in the direction of movement vector.
So my title might be a little confusing but basically I am working on a game that is side view ( Looks like 2d) but in 3d space. So currently it is a space game and I have a script that has artificial gravity on planets. So for instance if an object is flying left to right the planet will pull it in, and if the speed is correct it will start to orbit the planet. All of this happens on the X & Y plane and all objects are locked down on the Z axis (because of the 2d perspective).
Okay so all of that is working great, but what I am trying to do now is to get my object to face in the direction they are moving. So imagine a rocket ship flying around a planet clockwise, right now it just faces directly upward the whole time, I instead want the nose of the ship to turn as it rotates around. Does anyone have any way to do this? Specifically I ONLY want this rotation to happen on the Z axis (because of the 2d view), I tried doing some rotateTowards commands based on the forward vector of my object but it is not working as expected.
My only alternative strategy is to maybe make the object that is affected by gravity some tiny objects, then put the model of spaceship as a child object with no collision, and that script just rotates based on the forward vector of the parent? Any ideas would help. Thanks!
Your answer
Follow this Question
Related Questions
Grabbing the Relative eulerAngles.y of a Rotation 1 Answer
Why won't my model rotate up on X axis? 1 Answer
Vector3 and transform.rotation? 2 Answers
Unity 2D rotation not smooth? 0 Answers