I’m constantly changing the z value of my camera to create a nice effect (basicly moving the camera to the side). Altough this doesn’t function the way i want it to when my camera rotates, making it moving forward and backwards instead.
I’ve been trying to use transformDirection but i don’t seem to fully understand it because i never get the desired result. If i’m not wrong i need to change the local position to world position. So that’s my problem.
This is basicly what i’m doing.
MyVector.z = MyValue;
Transform.position = MyVector;
Thanks in advance for any slightest help, It’s greatly appreciated.
1 Answer
1
If you want to just “move the camera to the side”, try this in the Update() function (javascript):
var moveSpeed : float = 1;
transform.position += transform.right * moveSpeed * Time.deltaTime;
This will make the camera move ‘to the right’ at one unit per second. Change ‘moveSpeed’ to whatever you want. If you make ‘moveSpeed’ negative, it will move to the left.
“transform.right” is just a one-unit-long vector pointing quite literally ‘to the right’ from the transform. Time.deltaTime returns the amount of time since the last tick (or ‘frame’).
You can also use transform.forward and transform.up for motion along the x and y axes.
Good luck!
Can you show us the rest of your code a better description of the correct behavior? The code you show above should move the camera back and forth on the world Z axis regardless of the rotation of the camera. Is this what is happening? How is rotation changing things?
– robertbuYes the code above moves the camera according to the worlds z axis. And i'm trying to figure out a way to move the camera relative to it's rotation. Here's my actual code. cSharpConversion.y = MidPoint.y; cSharpConversion.z = MidPoint.z; transform.position = cSharpConversion;
– SimonDiamond