x


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.

more ▼

asked Jan 12 '10 at 12:47 PM

tyler gravatar image

tyler
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Feb 11 '10 at 05:18 AM

Ashkan_gc gravatar image

Ashkan_gc
9.3k 33 56 120

(comments are locked)
10|3000 characters needed characters left

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)

more ▼

answered Jan 13 '10 at 03:20 PM

Nephtysis gravatar image

Nephtysis
13 1 1 6

I'm not sure if "Transform.rotation; x = 0;" is from a programming 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.

Jul 17 '12 at 05:17 AM Muuskii
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5276
x3132
x2249
x1072

asked: Jan 12 '10 at 12:47 PM

Seen: 3176 times

Last Updated: Jul 17 '12 at 05:17 AM