Hi Everyone,
Is there a tutorial on how to allow the gameplayer to navigate the environment in the Unity3d/Maya way?
i.e Alt+RMB to zoom, Alth+MMB to pan, Alt+LMB to tumble??
My gratitude in advance.
El
Hi Everyone,
Is there a tutorial on how to allow the gameplayer to navigate the environment in the Unity3d/Maya way?
i.e Alt+RMB to zoom, Alth+MMB to pan, Alt+LMB to tumble??
My gratitude in advance.
El
I know of no such tutorial, but this is fairly simple.
On your camera, you would add a script which checks your input and then acts based upon it, like this:
UnityCamera.js
var rotateSpeed : float = 5.0f;
var moveSpeed : float = 1.0f;
var zoomSpeed : float = 20.0f;
var speedModifier : float = 5.0f;
function Update() {
camera.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
var sensitivity : float = 1.0f;
if(Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift"))
sensitivity *= speedModifier;
var x : float = Input.GetAxisRaw("Horizontal") * Time.deltaTime * 10.0;
var y : float = Input.GetAxisRaw("Vertical") * Time.deltaTime * 10.0;
transform.position.x += x * moveSpeed * speedModifier;
transform.position.z += y * moveSpeed * speedModifier;
x = Input.GetAxis("Mouse X");
y = Input.GetAxis("Mouse Y");
if(Input.GetMouseButton(1)) {//RMB
if(Input.GetKey("right alt") || Input.GetKey("left alt")) {
//You might want something more clever here
var zoomAmount = (x - y) * zoomSpeed * sensitivity;
if(camera.fieldOfView - zoomAmount < 1)
camera.fieldOfView = 1;
else if(camera.fieldOfView - zoomAmount > 179)
camera.fieldOfView = 179;
else camera.fieldOfView -= zoomAmount;
}
else {
transform.eulerAngles.y += x * rotateSpeed;
transform.eulerAngles.x -= y * rotateSpeed;
}
}
if(Input.GetMouseButton(2)) {//MMB
transform.position.x -= x * moveSpeed * sensitivity;
transform.position.y -= y * moveSpeed * sensitivity;
}
}
Also, keep in mind the difference between zoom and dolly. See this link for reference. Also, if you want more kinds of camera controls, check out this question.
Thank you very very much. Your code and the other reference are a great crash course in Unity !!
Take good care El
I recently had the need to make a similar script, and while Scott’s script is great it didn’t quite implement all the features I was looking for.
If you’re still struggling, feel free to grab this script and/or example project: http://danielskovli.com/folio/development/csharp/#maya-navigation-for-unity
Cheers,
Daniel
Hi,
I would like to rotate the camera whenever I hold down the left mouse button and drag either X or Y direction.
Please give me code and help me
Thanx in adavnce
Hi,
I am doing a small application, where I want to drag and drop any object that is picked by user with in the plane (i.e object should be drag-able within the floor). It should detect the collision also.
Hope I am clear to you all. Please give me code for this. Its urgent.
Help me to come out from this.