I'm a new user and I really enjoy discovering Unity3D. I'm more an artist than a programmer, so I have some difficulties to "translate" my thoughts into code.
The best would be to have a variable that allows me to make the rotation faster/slower per axis.
Here is what I have so far, but it doesn't work the way that is described in the images above :
Can you help me on that?
asked Sep 29 '10 at 09:37 AM
Your script seems to be on the right track. You should describe what your script is not doing when you post a script so that it is clearer what problem to solve.
What you describe is rather simple. Your code seems to be a bit confused about what eulerAngles are and you've left out some rather important details about your implementation.
In order to mirror the rotation about the right axis, you would apply this to your first camera
eulerAngles.x is your rotation about the right (x) axis and will make your camera look up or down. All you need to mirror the rotation is to set the rotation of your mimic camera to be the same as your lead camera.
To mirror all rotation, you would simply need:
You've left out the part where you are translating one of your cameras. I don't really know how you mean to move your camera so it's challenging to assume a given movement system.
Wherever you move your camera, you would need to do something like:
Here's a script to attach to your main camera that will move based on input axes;
From the slave perspective
Copying rotation is the same as copying position above, but replacing transform.position with transform.eulerAngles.
Considering things from the slave perspective is really spreading your code out. I assume this may be because you want the script to just work with a prefab and require little-to-no setup. You can achieve this from the master perspective by having the slaves add themselves to their master, changing the first scripting to something like:
If you cannot get your deltas directly or use input or some such (as in the case where using physics), you will have to calculate them manually.
Note that from the master's perspective, we only calculate their delta's once per frame, whereas from the slave perspective, every slave would have to re-calculate.
I have decided to break my setup into 2 distinct scripts :
Setup 1 : Camera 2 movement Camera 2 copies Camera 1 movements on X axis. moveSpeedX variable is used to control the scrolling speed.
Camera 1 movements script *Simplified for testing purposes*
Camera 2 copy Camera 1 movements script
I don't know how to save the initial transform.position in a Start() function and use it in Update() function. Or maybe something like transform.Globalposition.x = master_obj.Localposition.x * moveSpeedX exists in some way, and would do the trick?
With the help of the first answer I got, here is the setup I actually have :
On layer 1, Camera 1 is parented to the main character. On layer 2, Camera 2 is put in front of a background (image, or 3D scene in that case). Camera 2 copies Camera 1 orientation.
The main character is moving with the following script (simplified for testing)
Camera 1 is parented to the main character.
Camera 2 is the "slave" of Camera 1.
Being able to save the Camera 2 initial position would help me to change its position at startup and get something like the following image :
Setup 2 : Camera 2 orientation Simplified for testing purposes
Camera 2 copies Camera 1 orientation on its local axis. See images above.
I don't know how to save the initial transform.eulerAngles in a Start() function and use it in Update() function. Or maybe something like transform.Globalorientation.x = master_obj.Localorientation.x * moveSpeedX exists in some way, and would do the trick?
I don't know how to get the expected result. I am a bit confused about the way I can get it. I don't want my camera 2 to copy Camera 1 position but more like "ADD" it to its current position. I don't want my camera 2 to copy Camera 1 orientation but more like "ADD" it to its current orientation.
After that, I will try to implement the Camera 1 translation on x / Camera 2 rotation on Y axis.
I've tried to describe my question precisely.
Thank you again for your help.
answered Oct 02 '10 at 04:22 PM