unity3d相機切換效果
var camera0 : Camera;
var camera1 : Camera;
function Update () {
if (Input.GetKey ("1"))
{
camera1.enabled = true;
camera0.enabled = false;
}
if (Input.GetKey ("2"))
{
camera1.enabled = false;
camera0.enabled = true;
}
}
function OnGUI () {
GUI.Box (Rect (10,10,100,90), "Camera Switch");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Camera 1")) {
camera1.enabled = true;
camera0.enabled = false;
}
// Make the second button.
if (GUI.Button (Rect (20,70,80,20), "Camera 2")) {
camera1.enabled = false;
camera0.enabled = true;
}
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
鏡頭切換腳本
var _camera1 : Camera;
var _camera2 : Camera;
function Update ()
{
if (Input.GetKey ("1")) //如果敲擊鍵盤的"1"
{
_camera1.enabled = true; //camera1激活
_camera2.enabled = false; //camera1停止
}
if (Input.GetKey ("0")) //如果敲擊鍵盤的"0"
{
_camera1.enabled = false; //camera1停止
_camera2.enabled = true; //camera1激活
}
}
但是這個腳本不能使鏡頭恢復初始狀態,還在研究中。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
unity3d相機參數及同一場景中多個相機的應用
由 uke 於 星期日, 11/08/2009 - 18:35 發表
在unity3d中,相機是一個場景中必不可少的元素,相機就像是人的眼睛,三維場景的呈現,最后還是要通過相機來實現的。下圖為相機的屬性面板:
可以看出,相機物體與一般物體的區別即在於其有一個camera組件,下面我們來看看這個組件下的屬性參數都有什么作用.
clear flags:這個屬性用來設置此相機的畫面背景如何處理,共有四個選擇:天空盒,固定顏色,僅深度,不做處理。如果再多一個固定圖片的選項就好了,可以直接在此做背景圖了。
當選擇天空盒時,你將會在場景中看到你在場景渲染設置中所用到的天空盒畫面。當選擇固定顏色時,下面的background color即為用到的顏色。當選擇僅深度時,這個相機是沒有背景的,就好像這個相機渲染出了一個有深度的透明畫面一樣。最后一項不太明白在什么情況下使用。
normalized view port rect
這組參數是用來分割畫面的,只能分割成方形畫面,設置一坐標點及寬和高即可。可以做四格漫畫了,比較有用一組參數。
near clip plane
far clip plane
field of view
這三個參數直接決定此相機視野的深度和廣度,用過手動相機的朋友會比較明白。
orthographic 此參數將相機設為正交相機,既畫面沒有透視變化,如果你要做一些平面效果的話,那就使用正交相機。
orthographic size此參數設定正交相機的視野范圍。配合上一個參數使用。
Depth:設定多個相機的渲染先后順序。
cullingMask:比較有用的一個參數,設定當前相機的渲染對象層,類似於分層渲染,這樣就可以設定哪些對象可以被渲染,哪些對象不被渲染。配合layer使用。
targetTexture:指定渲染紋理。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
unity3d自定義曲線路徑
這個腳本可以讓你在U3D內設置曲線並讓物體沿着你設置的曲線進行運動。(教程最后面附源代碼下載地址)
1.新建一個空的GameOject(用來存放路徑點),在它的層次下新建幾個Cube作為路徑點,再新建一個GameOject作為運動的物體(Cube或Sqhere)。
2.為運動的物體添加SplineController腳本.
3. 如圖,選中移動物體對象,打開屬性面板,將存放路徑點的對象Game拖曳到上一步添加腳本后預留的接口上,系統將自動計算路徑,並以紅色線條顯示在場景中。
你可以通過改變路徑點Cube位置來調整路徑,或者添加新的路徑點,系統都會自動計算路徑,你要移動的物體將會沿着你設置的路徑移動。
4. 下面介紹添加腳本后生成的接口的作用,
Spline Root :自動計算路徑曲線接口。
Duration :移動一次所持續時間,即可以控制移動速度,默認10秒。
Orientation Modern :控制移動物體的角度、方向,可選兩項:
NODE:角度固定不變。
TANGENT:將與曲線正切動態改變角度。
Wrap Mode :循環模式,可選兩項:
ONCE:只運行一次。
LOOP:一直循環。
Auto Strart :是否自動計算曲線起始點。
Auto Close :是否自動計算曲線終結點。
Hide On Execute :程序運行后路徑點是否可見。
官方社區的一個例子,文章轉自:http://blog.sina.com.cn/s/blog_631388bf0100gzvr.html
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
攝像機路徑動畫及動畫錄制
Here's the Blender camera path project that I mentioned here. In the interest of focus (and size), I stripped out everything except the basics. I got the basic idea when I came across this page on making control-point-less bezier curve motion in Flash. Or rather, the control points are generated from the points already existing in the path. This way you can get nice curves straight from mesh data.
To use it, in Blender first make a straight line using the curve tool (if that isn't a contradiction ). Add -> Curve -> Bezier Curve, then press V to straighten the points, and then press Tab to leave edit mode. In the Link & Materials pane, call it "line". You only have to make one of these and you can use it with any number of 3D paths.
So, make a 3D path (Add -> Curve -> Path). In the Curve & Surface pane, click in the BevOb: field and type "line". This uses the bezier curve we made first to define the shape. In this case we just want a simple line so we can tilt the path and get surface normals from it later. Move points in the path by clicking on them and pressing G (Grab) then clicking again to place. Extend the path by selecting a point on the end and pressing E and clicking to place. Press T to tilt selected points left or right. Continue as long as you want, but if you're making a looping path, do not try to close the loop...just leave a gap between the first and last points. In the DefResolU: field, you can go very low; probably 1 is fine, or 2 if you want extra precision. Outside of edit mode, press option-C to convert the path to a mesh, and save it (be sure to make a copy of the pre-converted path, in case you want to go back and easily edit it later).
When you bring it into Unity, make sure that "Automatically calculate normals" is set to 180. Otherwise, if you did some funky things with the path (like 360 degree spins), Unity makes some extra points, which obviously messes up the end of the path.
When you place the path somewhere in your scene, you can position, rotate, and scale it however you want, and these transforms are accounted for properly. You can leave the mesh renderer on to visually see where the path goes exactly, and then disable the renderer when you have it positioned where you want it.
To make a camera go along the path, put the PathFollow script on it (I put it in the Camera-Control menu, but you can also use it for other objects). Drag the path from Blender onto the Path slot. Use Move Speed to control the overall speed of the camera movement, though relative speeds within the path are controlled by how far apart the points are. So if you want a completely even speed, make all the points pretty much the same distance apart from each other.
Direction is either forward or backward, though backward just traverses the points in reverse order; it doesn't make the camera face backward or anything. The little arrows you see in Blender, conveniently enough, tell you what direction the path goes in.
Movement Only makes the camera follow the points through space, but leaves the rotation alone so the camera stays facing the direction it's in when it starts. Typically you'd use this with the Motion Record script (see below) to add manual rotation to all the points.
Loop...I'm sure you can figure that one out.
Startpoint starts the camera movement at a given point. So if you have a path made up of 120 points, using 60 for Startpoint makes the camera start halfway along the path.
Endpoint ends the camera movement at a given point, counting backwards from the last point. It only works in non-looping mode. If you're not looping, this should be set to at least 3, or else movement data from the first few points "bleeds" into the last few. This is how loop mode works, but you typically don't want that for non-looping.
Ease in and Ease out are for starting and ending smoothly. Intended for non-looping mode.
"Object to track" is a transform, which if used makes the camera always point at that object as it moves along the path. If this is none, then it has no effect.
Rotation Data is a string generated by Motion Record. If you leave it empty, it does nothing.
Zoom Data is also a string generated by Motion Record. If left empty, it does nothing. Otherwise it behaves like Rotation Data, but changes the zoom (field of view).
The rest of the variables you can ignore, but they need to be public for MotionRecord to access...is there a way to do hidden public variables? (Short of static, which won't work in this case since you might want to use multiple objects on paths at once).
The use of Motion Record is detailed in the next post.
動畫錄制
OK, docs for Motion Record:
If you want to add extra rotation to camera path movement, either in combination with Movement Only or just to add some additional rotation to that which you get from the path itself, put the Motion Record script on the same camera that's using the Path Follow script. This allows you to steer the view with the mouse/keyboard as the camera goes along, and edit each point afterward if you want.
(My Storm City demo uses Movement Only with manual rotation for the helicopter--this allows the helicopter to move along the path, with the manual rotation making it behave more like a helicopter. It also uses regular mode--not Movement Only--with extra manual rotation for the chase viewpoint, in order to get a sort of "hand-held" movement which you can't get from the path alone. The car demo in that same topic uses regular mode without any extra rotation, with the Object To Track set to the car.)
You also need the three Motion Record GUI objects, which exist as a prefab. Probably easiest to make a package of this and import it into whatever project you want.
Sensitivity is how sensitive the mouse controls are. Key Sensitivity is how sensitive the keyboard controls are for motion. Invert Y Axis does just that, and File Name is the name of a text file that will be generated when you're done. This gets put in the base folder of the project, outside of Assets, because it's not used directly.
When you run the scene, you'll see "Recording" in the lower right. This means you can move the view around as you go along the path, and the rotation and/or zoom at each point is recorded. If it says Rotation/Zoom, then you are recording both. If it says Rotation, then you're using zoom data that you recorded before and put on the camera, so you're only recording rotation, but you can edit the zoom. If it says Zoom, then you've got some rotation data, so you're only recording zoom, but you can edit the rotation. If you have both rotation and zoom data, then you can only edit them. If you remove the rotation and/or zoom data from the camera, then you can record them again.
The % in the upper left is what point you're on at the moment, out of the total number of points in the path.
Press H to get a reminder of keyboard commands. (Or the help key, theoretically, though it doesn't seem to work even though Unity doesn't object to the name.) These are:
WSAD to rotate the view on the X and Y axes instead of/in addition to the mouse. ZX or < > (really . and ,) rotates on the forward axis. [ (left bracket) zooms out, ] (right bracket) zooms in. Hold down shift to make the movement go 10 times slower for fine control. Press space to reset all axes to 0 and the zoom back to the field of view you started out with (usually 60, unless you've changed it).
Press 0 (zero) to set the overall speed to none. That way you can move the view around as much as you want at that point before continuing. Press 1 to go back to 100% speed, or 2 to go 10X faster. Press + and - (really = and -) or left and right arrows to go a little bit faster or slower. It's sometimes useful to go in slow-motion...I did most of the helicopter movement in one "take" that way, with a little editing afterward. On the other hand, the viewpoint movement was done in real-time to get a sort of hand-held feel.
When you get to the end of the path, or if you press Q, then the rotation data is saved to a text file with the specified name. Open this file up and select all, then copy, then switch back to Unity and paste into the Rotation Data field on the Path Follow script. (Yep, the whole thing will fit even if you've got zillions of points.) This may seem slightly clunky, but I can't think of any other way to do this, short of just reading a data file directly, which I don't want to do because I want the data to be self-contained in the project. Any suggestions welcome.
If you run the scene again with data in the Rotation Data field, you can then edit each point. "Recording" no longer shows, to be replaced by "Edit" if you're in edit mode. Controls as above, except you normally can't rotate the view, but now you can press E to enter edit mode. This allows you to change the rotation of whatever point you're at (see upper left display). E again goes back to movement mode (or you can use 1 or 2 to jump to that speed and exit edit mode at the same time). Press up or down arrows to jump to the next or previous point (and enter edit mode if it's not active already). Again, pressing Q or reaching the end of the path will save the edited data, which you can then paste into the Rotation Data field, overwriting the original data. Probably a good idea to use different names for the files so you can go back to the pre-edited version if necessary.
Keep in mind that you're just creating/editing rotations on each point in the path, so the Path Follow script is generating bezier curves on the fly. This means that playback will probably not exactly match what you did when recording. It's useful after editing some points to go backward before those points and then enter play mode to see exactly what you did. If you want finer control, make the path resolution higher in Blender (and adjust Move Speed to compensate).
And I think that's about it, unless I forgot something.... If anyone uses this, let me know if you find any bugs/problems. Also let me know if you think of some additional functionality. Or better yet, implement it yourself and post it. I can already think of an external view mode for editing the rotation of objects on the path, though it was surprisingly intuitive to do the helicopter rotation from first-person mode...also quite a bit faster than external editing would be, I think.
--Eric
Last edited by Eric5h5 on Mon Jul 02, 2007 7:37 pm; edited 3 times in total
原貼地址:http://forum.unity3d.com/viewtopic.php?t=5898&highlight=gui+motio