- Home /
Having camera point and shift around origin?
I'm creating a game that is played on a plane that is separated into four quadrants. I want a to only look at one quadrant at each time with the rotation (35, 45, 0). Is there anyway to have the camera rotate around a point (most likely origin in this case) to the next defined location (aka, the next quadrant) instead of switching cameras? I feel like having the camera rotate at a speedy, but smooth, pace will keep gameplay flowing perfectly as this is going to be a quick-styled game.
Just to clarify my question. I don't want to rotate the camera in its spot, I would like to have the camera move from (-79, 50, -79) to (79, 50, 79) (etc) but ins$$anonymous$$d of just zapping to the spot, I want it to rotate from the first spot to the second spot. Is this possible? Hopefully I am explaining this well enough; if not just say so and I will create a quick photo explaining better.
Answer by nisovin · Apr 07, 2016 at 05:21 AM
Create an empty game object and make it the parent of the camera. Put that empty game object at the origin, and have the camera at the correct position looking at the origin. Now when you rotate the empty game object, the camera will rotate around that spot.
You can use Quaternion.RotateTowards if you want to smoothly rotate the camera over time.
http://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html
I'll test this later and report back. It seems there's always a pretty easy solution to my problems. I need to start thinking outside of the box. Thank you!
How would you suggest setting it up to where it would stop at a certain point? Right now the camera position to look at quadrant 1 would be (-80, 55, -80) rotated (37.5, 45, 0). To go to quadrant 2, it would be (80, 55, -80) rotate (37.5, -45, 0). How could I rotate from the first position to the second position?
Just use that function I gave you. You just need the target rotation.
Your other option here is to just set up game objects that already have the positions and rotations you want. Then you can use Quaternion.RotateTowards and Vector3.$$anonymous$$oveTowards to adjust the camera to those predefined positions.
On that function it asks for from, to, and maxDegrees. I'm not sure what to put for from and to, to make it go to the second position?
At some point you have to just try it and see. If you've set it up the way I told you, I suspect your numbers are wrong, since you should be rotation the game object, not the camera. But you can't know without trying. I've given you all of the information you need, I can't really do much else without creating your game for you.
I actually recommend now that you just take my second suggestion of setting up objects that already have the positions and rotations you want, and use their rotations/positions in your script rather than inputting the numbers directly.
Okay I seem to have it setup. I didn't realize I had to create another gameobject change the rotation and yeah. Thank you.
Your answer
Follow this Question
Related Questions
Can you offset the dead zone of Cinemachine's camera from the center? 0 Answers
I need to find a way to pan my camera around an object. 1 Answer
Camera gets stuck when cursor is locked 0 Answers
How to rotate the camera with the player smoothly without the camera snapping back and forth? 2 Answers
How to orbit camera around player from top-down to sidescroller view? 1 Answer