- Home /
Camera behavior the same as the unity editor has
Hi guys i want to create the same camera behavior as the scene view camera in unity.
moving with arrows on X/Z axis , rotating the camera just during holding the right mouse button and zooming with mouse wheel .. any ideas ?
The moving part is done ... it works perfectly , i tried just modify the MouseLook script with if (Input.GetMouseButtonDown(1))
but it doesnt work as i expected .
ok i fixed it with if (Input.Get$$anonymous$$ouseButtonDown(1)){ rightclicked = true; } if (Input.Get$$anonymous$$ouseButtonUp(1)){ rightclicked = false; }
it has only one problem ..
i am using this script to moving my camera
public float speed = 10.0f;
void Update()
{
Vector3 movement = Vector3.zero;
if (Input.Get$$anonymous$$ey("w"))
movement.z++;
if (Input.Get$$anonymous$$ey("s"))
movement.z--;
if (Input.Get$$anonymous$$ey("a"))
movement.x--;
if (Input.Get$$anonymous$$ey("d"))
movement.x++;
transform.Translate(movement * speed * Time.deltaTime, Space.World);
}
and the modified mouseLook script ... how can i fix the moving script to move according to rotation of the camera ?
Don't answer you own question with a comment, ins$$anonymous$$d edit your question.
Answer by Benproductions1 · Feb 18, 2013 at 03:24 AM
Hello,
I'm not going to go over the scroll wheel, since even I don't know how that works in Unity... it changes some other camera stuff too. Also I'm not going to go over increasing speed using shift or just moving more. As you have already suceeded im making the mouse make the camera look, I'll just make it move :)
function Update() {
//Here you have the looking, whch you already have :)
//First, lets check if left mouse is down
if (Input.GetMouseButton(1)) {
//Now lets move according to the direction
//first forwards and backwards
transform.position += transform.forward*Input.GetAxis("Vertical");
//then sideways
transform.position += transform.right*Input.GetAxis("Horizontal");
}
}
Hope this helps, Benproductions1
Answer by idbrii · Feb 20, 2018 at 05:08 PM
FlyCam_Extended shows how to implement movement and looking. It also shows moving faster/slower.
To limit movement to right mouse click, you can wrap the changes to transform.localRotation in transform.position with if (Input.GetMouseButton(1))
(as Benproductions1 showed).
Doing middle click panning would essentially be adding rotationX/Y to transform.position inside an if (Input.GetMouseButton(2))
block.