Unity 相机控制集合。。。。

 

 

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值