# Transform Space vs Self

Hello again everyone. I am having another issue yet again. Heres a simple snippet of what i have.

transform.Rotate(Vector3(0, 1, 0), Space.World);

Now i thought , that because i have set it to use the global axis, not the local, that when i rotate it, the z, and x axis would also move, because of course , you are rotating around the y. Thats not how it works for me at all. Instead , the object does indeed rotate around the world Y, but the world Z, and X stay exactly where they are. I speculate , even the Y is not changing , so much as the objects just rotating locally around that global y axis.

My problem really is that , i have a camera, angled down toward the ground. So locally , its Z is slanted downwards. I always want the to be the perspective, but i want to be able to rotate the camera as i can, and also move it side to side , back and forth across the ground. The rotation is working beuatifully, the camera moves fine, but i need to be able to change the global Z direction. If a player rotates the camera, it should be driving back and forth , side to side in respect to the cameras new angle.

Im not sure if this makes any sense or not, but the bottom line is , i need to be able to have the global Z and X axis’ turning direction based on the objects rotation around its global Y. I cant drive the camera in the local z direction , cause it will drive in to the ground.

EDIT : heres a snippet from what i have so far.

``````var rotatingCam : boolean = false;
var storedMousePos : Vector2;
var relativeMove : Vector3;

function Awake(){
storedMousePos = new Vector2(0, 0);
}

function Update () {
if(Input.GetKey(KeyCode.UpArrow)){
transform.position.z += 1;
}
if(Input.GetKey(KeyCode.DownArrow)){
transform.position.z -= 1;
}
if(Input.GetKey(KeyCode.LeftArrow)){
transform.position.x -= 1;
}
if(Input.GetKey(KeyCode.RightArrow)){
transform.position.x += 1;
}
if(Input.GetKey(KeyCode.LeftAlt)  !rotatingCam){
if(Input.GetMouseButton(0)){
storedMousePos = Input.mousePosition;
rotatingCam = true;
}
}
if(rotatingCam){
if(Input.GetMouseButton(0)){
if(Input.mousePosition.x > storedMousePos.x){
transform.Rotate(Vector3(0, 1, 0), Space.World);
}
else
{
transform.Rotate(Vector3(0, -1, 0), Space.World);
}
}
else{ rotatingCam = false; }
}
}
``````

just a quick bump, im totally perplexed as to how to achieve this.

One last bump. Really, no one? Im sure this is something simple… i just cant seem to find the answer anywhere.

The global axes are global because that’s what they are. You can’t change them. The global axes are like the anchors of the coordinate system. If they rotate, which is of course impossible, then everything in the scene will rotate accordingly. That’s the whole point of having the local axes. When an object is rotated, its local axes rotate with it. What I’m reading from your OP is that you want a second set of local axes, and are misguidedly trying to turn the global axes into local axes (which defeats the purpose of having global axes in the first place).

Having said all that, I don’t quite understand what you’re trying to do. From your description, it seems to me that all you really want to do is shift the position of the camera while it’s rotated. Is that right?

I want to have the forward direction the camera is moving in , change based on the direction you have rotated the camera. Hopefully that makes more sense.

So if, for example, the camera is not rotated about a particular axis, then you want the camera to move forward, while if the camera is rotated some number of degrees about that same axis, then it should follow a different direction? Is the different direction going to be based off an offset or a rotational value? Can you give me an example of some values that you expect? I’m almost getting what you want, but it still seems to me that this can all be accomplished by a basic position offset.

Hmm , i am not sure i can descrive it any better than that. I will try once more though.

Camera moves forward , backwards, side to side strafing. It also can rotate around and around. Atm it simply moves forward and backward in one direction, no matter what way you rotate the view to. I would like the camera to move forward in the direction you rotate it to always, and still maintain all of its functionality.

Oh, you should’ve said that in the first place. XD

To reference the local z-axes of the game object, just use transform.forward. So transform.Translate(transform.forward, Space.World) would move your game object in whichever forward direction your game object is facing. transform.Translate(Vector3.forward) does the same thing.

Ahh yea i knew that , but theres a problem, as i said above. The camera is facing down angled. Like in a RTS game. So i cant use that local Z axis to move it forward, or it drives into and through the ground :(. Thats why i originally started all this discussion. Looking for a way to fix that issue.

Then just clamp the y-component of your camera’s position within some range.

Thats where you lost me, im kinda new to unity , not sure i know how to clamp the y value like you describe. (or for that matter what it means).

Mathf.Clamp(A, B, C)

That line will clamp the value of A between B and C. So if B = 10 and C = 20, then A will be returned clamped according to that range. If A = 15, then it will be returned as 15 because it’s between B and C. If A = 9, then it will be returned as 10 because A is not allowed to have a value outside the range and 10 is the closest number in the range.If A = 21, then it will be returned as 20 because A is not allowed to have a value outside the range and 20 is the closest number in the range. You just supply the function with whatever values of A, B and C suit your purpose.

In your case, you pass the y-component of your camera’s position as A, while B and C would be a range of heights which you choose yourself. You perform the clamp immediately after the camera moves.

So basically, you call:

Mathf.Clamp(transform.position.y, LOW_HEIGHT, HIGH_HEIGHT)

You might want to optimize your code after you’re finished adding stuff to it though.

Dood, you *^%'n rock Thanks for taking the time to explain that out directly, got it, sweet. Cameras now doin the trick , lil buggy but im so damn tired now , work all day unity all night , time for bed, Thanks again m8.