Movement relative to world axis&local rotation

I’ve just started out with Unity, so apologies if this is a stupid question, but I’ve searched high and low for an answer.

I have a camera that is pointing downwards at a 45 degree angle(45,0,0), and it will always remain at this angle. You can rotate the camera around a fixed point(A fake gameObject following the focal point of the camera). The bit I am struggling with is the panning of the camera. I want it to pan across a fix plane, so it should not move up or down, only left, right, forward or backwards. Because of the rotation the left/right movement is just a world.self translate, but when I try to translate the forward/backward movement it moves relative to the camera and starts to move along both the Y and Z axis(Essentially zooming in).

I tried setting the translate to self.world, which works ok at the start, but when you rotate the camera it continues to move along worlds Z axis which is wrong.

So I want to pan across the Z world axis, but in a relative direction to the cameras rotation.

I hope I explained that all ok :slight_smile: Here’s the parts of my movement code that are relevant.

transform.Translate(horzMoveAmt,0.0f,0.0f,Space.Self);
    			
//Does not work when rotated		
transform.Translate(0.0f,0.0f,vertMoveAmt,World.Self);

You have two things that you can do. The first thing is to make the camera reset its x-axis rotation (0, 0, 0), then rotate it, and then rotate the x-axis back (45, 0, 0). Granted, this is a bit sloppy, but it will do what you want.

The second option is to actually nest the camera into the object that it is always looking at (or an empty object at the same location). then all you will need to do is rotate that object and the camera will rotate the way you want.

Subtract the location of the focal point from the location of the camera. Moving +/- along this vector will move the camera closer or farther. Save this off (or don’t reevaluate) if you want the camera to stay on the same plane.

The cross product between Vector3.up and the vector determined above will yield a vector orthogonal to both. Moving the camera +/- along this vector will pan it.

I think you should put the Camera in a gameobject and move that instead of trying to move the camera