- Home /
Camera Orbit for spaceship
There is a lot of help for orbital cameras. And the best one if of course provided by unity wiki MouseOrbitImproved.
I am trying to use this script for a spaceship that can also rotate on its z axis.
This is is how i have my objects set up.
-Spaceship
-FlyCam(GameObject)
--FlyCamera(Camera)
The FlyCamera has a script that tells the parent FlyCam to follow the spaceship if the spaceship moves.
I added the MouseOrbitImproved script to FlyCamera and on start it is disabled. If I press and hold Left Control, I can orbit the spaceship. When I release Left Control, x and y get reset back to 0. Everything works well if I fly in a straight line and the script is active. If I let got of Left Control and change my y or z axis, and activate the script, the camera still orbits the object, but not using the correct axis.
Initially, This is what it looks like if I fly in a straight line and I don't change direction.
I can activate the orbit script and it will orbit correctly. Now if I disable and I continue to fly, but this time I change direction and go straight up 90 degrees. If I activate the orbit script, it will look like this.
This is not how it should be though, it should be like in the first image.
Is there any way I can always keep the orbital camera behind the spaceship like in the first image every time i activate the script?
If there is any resource I may have missed that already answers this question, I'm sorry. I tried to search before I asked, but i could not find a solution that involved the z axis. they all deal with only x and y axis assuming the object's y axis is always up.
Any help would be appreciated. Thank you in advance.
So you want to use the spaceships up axis as the axis to rotate around ins$$anonymous$$d of the world up axis? So the camera will also look up if its behind a spaceship facing upwards?
Yes, exactly. That's why I have the FlyCam game object as a parent of FlyCamera. so its position and rotation remains zero, and FlyCam is the one that changes rotation and position as the spaceship rotates or moves. The Orbit is attached to the child of FlyCam, the one that is Zero for position and rotation, so I don't see why it would not work, but for some reason, the child is taking into account its parent rotation.
Do you only set the position of the FlyCam Object or also the rotation? Bacause if you dont set the rotation the orientation will stay the same and thus the y-axis will still be pointing upwards in worldspace.
Once the script is deactivated, then all rotation and position is reset for FlyCam object back to be behind the spaceship.
Answer by Doctor06 · Jan 27, 2017 at 12:55 AM
For those of you who find this question. I'll redirect you to where i found a good solution to the question.