- Home /
top down 3d camera rotation question
How do you control the max amount of rotation of an object ? and / or How to you fix an 'axis' of rotation ?
Here is the example :
I have a camera looking down onto a scene, smoothly following the player. The camera is at a fixed position and rotates. How do I stop the camera rotating after a cetain amount of rotation and/or not rotate on a specifc axis. i.e I want 'north' to remain 'north' for the player and for the camera to no show too much of 'offmap'.
thanks for any help on this.
Answer by Ashkan_gc · Feb 11, 2010 at 05:18 AM
simply check the ammount of rotation of your camera and if it's larger or smaller than what you want clamp it to max or min value. your rotation is arrount the y axis i think. also you can use clamp method when you want to rotate your object and don't allow it to have a value larger/smaller than what you want. use Transform.rotate to rotate your camera. if you use other's scripts for camera movement still you can check for out of range values and change them in camera's lateUpdate function in a script.
Answer by Nephtysis · Jan 13, 2010 at 03:20 PM
You can place the camera behind the FPC and give it the same movement script (=same speed) as the FPC. This way the camera will continue to 'follow' your character, but without the rotation at all. Do make sure that speed is equal and that the direction they're looking at is the same.
If you want to be able to 'look around' you can give the camera the MouseLook script, and I'd think you'd want to combine that with a script that says:
when "jump" is pressed, go to rotation (0, 0, 0) //=looking forward again. (For now I got:
function Update () {
if (Input.GetButtonDown("Jump"));
Transform.rotation; x = 0;
Transform.rotation; y = 0;
Transform.rotation; z = 0;
}
but I do get an error: "BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'rotation'." I know I have to add something in the first line here, still puzzling :P)
I just tried it while the camera was looking just a bit different then the FPS and it caused them to go different ways, because 'forward' meant something different to my camera then my FPS. I'm not sure this is what you want completely, but let me know what you think of this and we'll work something out here :)
(ps: not that good at scripting yet, so therefor not rightly posted here, maybe I'll have a shot at it later today and see if I can fix it)
I'm not sure if "Transform.rotation; x = 0;" is from a program$$anonymous$$g language that I do not know, but if I were a betting man I would wager that you meant transform.rotation.eulerAngles.x = 0; note the capitalization (or lack thereof) of the transform keyword. Also, realize that such an operation (iirc) is illegal in C# and would never compile.
If that's what you meant you could have replaced all three lines with "transform.rotation = Quaternion.identity;"
I don't mean to criticize someone who is just trying to help, it just seems like your suggestion has some inconsistencies.
Your answer
Follow this Question
Related Questions
Using the accelerometer to rotate Camera 1 Answer
Backgrounds moving at different speeds? 1 Answer
Simple script to follow player only shows the camera background 1 Answer
I am getting a problem with moving and rotating a camera! 1 Answer
How can I rotate an object towards the mouse in only one axis? 1 Answer