Pages: [1]   Go Down
  Print  
Author Topic: Viewport Style Navigation - A camera script  (Read 559 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
sixbelo
Global Moderator
Newbie
****

Karma: +2/-0
Offline Offline

Posts: 62



WWW
« on: January 22, 2010, 02:24:49 PM »

Hi guys.

When I created a webplayer for my challenge entry I wasn't happy with the MouseOrbit script to show off the model. So I made a new script to have more of a 3D app style navigation like that of C4D and the Unity Editor using the Alt+Mouse buttons for orbiting and zooming. When trying to figure out how to deal with panning I found and borrowed some stuff from unifycommunity.com and ended up with the creating script below in case you guys want to use it.

Editor Usage:
1. Add Component to your camera either through Component->Camera-Control->Viewport Style Navigation or dragging the script on to your camera.
2. Add an existing GameComponent from your Hierarchy on the Target setting of the script or select one from the Target drop down.
3. In the Inspector you can change settings to suit your model or scene and toggle enabling zoom and pan independently if you want.

I want to add Editor elements so you can visually see where the camera can move and everything at some point. Also I want to have an option where you can choose between different styles of navigation without having to touch the code. Like a drop down or something where you can select "Lightwave" or "Cinema4D" style navigation. Maybe even a "Help" toggle so the controls are there and you don't have to worry about adding it.

Right now the controls are:
Orbit: LMB
Zoom: RMB or Alt+LMB
Pan: MMB or Alt+Shift+LMB

I decided to leave off the Alt key as a modifier when using middle and right mouse buttons. Notice the support for a one button mouse (which I guess it complete unnecessary, but you never know)

Just download the attached file or check it out in a webplayer demo and download from here.

If you run into any problems let me know or if you have any ideas on how to make it better let me know. Or even if you think this is a waste and there is already some super awesome script let me know. Smiley

I like Boo, but if you'd rather have it in JavaScript and/or C# let me know and I can convert it to those. I'm trying to set it up so that you don't have to mess with the code at all unless you really want to.

Notes
Remember to set the disableContextMenu parameter for your webplayer to true or when you try to zoom you will get Unity's context menu.

Updates
Added spheres that display in Editor to show Zoom control. This way you can see in the editor how far the camera will zoom in and out.

* ViewportStyleNavigation.boo (4.48 KB - downloaded 29 times.)
« Last Edit: January 22, 2010, 08:29:14 PM by pikusuru » Logged

Ninjas!

twitter | tumblr
Thomas P.
Administrator
Sr. Member
*****

Karma: +51/-0
Offline Offline

Posts: 783


Forging The Holy Poly!


WWW
« Reply #1 on: January 22, 2010, 02:39:17 PM »

Sweet! Will have to give that a try later Smiley
Logged

-----------------------------------------------
Thomas Pasieka - Freelance 3D Artist
I am available for contract work. Please contact me.
http://www.3dattack.us
sixbelo
Global Moderator
Newbie
****

Karma: +2/-0
Offline Offline

Posts: 62



WWW
« Reply #2 on: January 22, 2010, 04:25:33 PM »

Cool! Please do and let me know what you think.

I added a kind of gizmo that lets you see the camera's range of movement around the target. Its disabled by default but you can enable it by checking Enable Custom Gizmos in the Inspector.

I like it but think its probably distracting and off-putting if it were displayed initially.
« Last Edit: January 22, 2010, 04:29:01 PM by pikusuru » Logged

Ninjas!

twitter | tumblr
droffset
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 15



WWW
« Reply #3 on: January 22, 2010, 05:11:36 PM »

I was daydreaming about having this exact thing just the other day.  Thanks for sharing!
Logged
sixbelo
Global Moderator
Newbie
****

Karma: +2/-0
Offline Offline

Posts: 62



WWW
« Reply #4 on: January 22, 2010, 08:35:43 PM »

@droffset: NP. Let me know if you have any problems or ideas with it.

Well found one problem I need to fix. Sad When you drag the the browser window or standalone player window it registers as orbiting to the script. I assumed clicks would only register if in the content view.

Edit: The normal MouseOrbit script has the same issue, but I still want to fix it.
« Last Edit: January 23, 2010, 09:05:16 AM by pikusuru » Logged

Ninjas!

twitter | tumblr
narven
Newbie
*

Karma: +3/-0
Offline Offline

Posts: 58



WWW
« Reply #5 on: May 17, 2010, 07:27:24 AM »

I've tested that script, but there are some problems, at least in my project.

Even if we change the scroll settings and speed the mouse wheel jumps to both limits at once (far and near)

the pan didnt work for me.

im going to convert it to c# to try to understand it.
ill post it if i can find resolution to my problems Cheesy
Logged

there's something about the web...
http://www.narvenblog.com
dotmanx
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 1


« Reply #6 on: May 25, 2010, 02:04:11 PM »

Pls can u make this out in javascript...thanks a bunch....u can send it to my mail...

dotmanx@yahoo.com
Logged
sixbelo
Global Moderator
Newbie
****

Karma: +2/-0
Offline Offline

Posts: 62



WWW
« Reply #7 on: July 02, 2010, 10:54:47 PM »

I've tested that script, but there are some problems, at least in my project.

Even if we change the scroll settings and speed the mouse wheel jumps to both limits at once (far and near)

the pan didnt work for me.

im going to convert it to c# to try to understand it.
ill post it if i can find resolution to my problems Cheesy

Yeah, so this is a bit late. Smiley

I really appreciate you trying it out and mentioning the problems you were having.

I can see the zooming with the scroll wheel potentially posing problems as I think I had to fiddle with a multiplier to get it to work on my system. 20 worked for me on my Mac and PC, but I never exposed it as a variable so that it could be easily changed or took more time to find a better solution since it seemed to work in my tests.

The pan issue surprises me though as its worked with no problem across multiple systems. I'd be curious to know if it fails with just MMB and/or Alt+Shift+LMB.

If you found resolutions I'd be interested hear what you found.

@dotmanx: In light of narven's findings I'm a bit hesitant.
Logged

Ninjas!

twitter | tumblr
Insectscorch
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 10



WWW
« Reply #8 on: July 30, 2010, 01:36:48 PM »

It works OK on my project. It's very useful for communication between team members. I can showcase my work so I can get opinions.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: