Edit: Think i got it solved, or at least iam a step further :). The following thread is a great ressource
WOW Camera Movement
The new flawlessly working script you can find in the 3rd post
Here the old Post:
Ok, first post so hello everyone. Excuse me for my newbish question, but i tried that thing for hours now and i cant get it to work… What i actually want is the following:
1.Get player camera position at start of this camera control script
2.Store the value in a custom vector3
3. use the y.value of the custom.vector3 to determine default zoom distance
4. Set a min/max value for min/max zoom distance
for 1 2.
So first i wanted to declare a variable vector3 outside of the functions in which the cameras start position is going to be stored. then i wanted to equal that vector 3 with the ones that i can get from Camera.current.transform.position
in the Start function.
the rest i wanna figure myself, but i cant get 1 2 to work without knowing how to. I appreciate any help or pointers in the right direction. My first custom script… took me a whole day and i actually dont want to spend more time on it, so help me finish it tonight ![]()
And here the complete script i made so far. I know you will see the problem with the vector3 and the Camera.current.transform.position but i have actually no idea how to put it right. Tried a lot of combinations now… Anyway, pls have a look. Works like a charm except that vector3 stuff
var arrowkeyspeed = 1.0;
var mousescrollbuttonspeed = 1.0;
var mouse3rdbuttonzoomspeed = 1.0;
var panspeed = 1.0;
var maxzoomin = 1.0;
var maxzoomout = 1.0;
var defaultcameraposition.Vector3 : Vector3;
function Start () {
defaultcameraposition = Camera.current.transform.position;
}
function Update () {
// use the left/right key to move camera to left or right direction
var moveleftrightkeys = Input.GetAxis ("Horizontal") * arrowkeyspeed;
moveleftrightkeys *= Time.deltaTime;
transform.Translate (moveleftrightkeys, 0, 0 );
//use the up/down key to move camera to up or down direction
var moveupdownkeys = Input.GetAxis ("Vertical") * arrowkeyspeed ;
moveupdownkeys *= Time.deltaTime;
transform.Translate (0, moveupdownkeys , 0);
//zoom in/out turning the mouse wheel
var zoominoutmousescroll = Input.GetAxis ("Mouse ScrollWheel") * mousescrollbuttonspeed;
zoominoutmousescroll *= Time.deltaTime;
transform.Translate (0, 0 , zoominoutmousescroll);
//zoom in/out holding 3rd mousebutton and moving mouse up or down
if (Input.GetButton ("Fire3")) {
var zoominoutmouse3rdbutton = Input.GetAxis("Mouse Y") * mouse3rdbuttonzoomspeed;
zoominoutmouse3rdbutton *= Time.deltaTime;
transform.Translate (0, 0 , zoominoutmouse3rdbutton);
}
// pan direction holding right mouse button and dragging into desired direction
if (Input.GetButton("Fire2")) {
var panmouse2ndbuttonx = Input.GetAxis("Mouse X") * panspeed;
panmouse2ndbuttonx *= -Time.deltaTime;
var panmouse2ndbuttony = Input.GetAxis("Mouse Y") * panspeed;
panmouse2ndbuttony *= -Time.deltaTime;
transform.Translate ( panmouse2ndbuttonx , 0 , 0 );
transform.Translate ( 0 , panmouse2ndbuttony , 0);
}
}
@script RequireComponent(CharacterController)