- Home /
Setting z value of trans.pos relative to rotation
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.
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?
Yes 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 = $$anonymous$$idPoint.y;
cSharpConversion.z = $$anonymous$$idPoint.z;
transform.position = cSharpConversion;
Answer by SergeantBiscuits · Apr 24, 2013 at 09:49 AM
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!
Thanks for the help! Unfortunately i've done some math i just can't simply implement in transform.right. Thanks for the help anyways
Your answer
Follow this Question
Related Questions
Rotate an object such that it is theta degrees relative to another object 1 Answer
Tilt with rotation. 0 Answers
how to move an object, but make it stay on the ground 1 Answer
Global movement 0 Answers
Camera Relative Movement 2 Answers