x


Unity3d or Maya-style Camera navigation

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

more ▼

asked Oct 14 '10 at 11:19 AM

El Mustafa gravatar image

El Mustafa
2 1 1 1

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Oct 14 '10 at 04:43 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Apr 13 '12 at 05:09 PM

danielskovli gravatar image

danielskovli
1

(comments are locked)
10|3000 characters needed characters left

Thank you very very much. Your code and the other reference are a great crash course in Unity !!

Take good care El

more ▼

answered Oct 16 '10 at 03:25 PM

El Mustafa gravatar image

El Mustafa
2 1 1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3014
x843
x400
x102
x57

asked: Oct 14 '10 at 11:19 AM

Seen: 2234 times

Last Updated: Apr 13 '12 at 05:09 PM