unity camera smooth

Today, I started to look at the third example in the android development paradigm. Here I noticed the use of this function Mathf.SmoothDamp, which is used for the buffer tracking of the camera in the game. In fact, we will notice that some games use the function of smoothmove, which is actually similar In effect, I just found that this function has been easily packaged. I checked the official website documentation and found that it is really very simple to use.

smoothdamp, my understanding is a smooth buffer, something is not a rigid movement but a deceleration buffer movement to a specified position. Let's look at the code:

1
2
3
4
5
6
7
8
public  Transform target;         //The player
     public  float  smoothTime= 0.3f;   //Smooth Time
     private  Vector2 velocity;        //Velocity
     void   Update ()
     {
         //Set the position
         transform.position =  new  Vector3(Mathf.SmoothDamp(transform.position.x, target.position.x,  ref  velocity.x, smoothTime),Mathf.SmoothDamp( transform.position.y, target.position.y,  ref  velocity.y, smoothTime),transform.position.z);
     }

Here is a little explanation, target (tracked target), smoothtime (buffering time, the longer the time, the slower the buffering speed and the slower the movement), velocity (relative buffering deceleration, it looks very complicated and complicated, in fact we don't need it at all Ignore him, it is only used as a bearing variable, we just need to assign the default value to 0.)

In the update, the object (actually the camera) is moved to the x-axis and y-axis, because it is a horizontal version of the game~, you can actually specify the velocity as a float value and use it directly.

Okay, that's about it, I hope it helps you~


Source https://blog.csdn.net/u011285268/article/details/922938 


Make up for the unity camera knowledge

There is a difference between orthographic (without vanishing point projection)  and perspective Perspective (with vanishing point projection) in projection

 orthographic


Can't judge distance

Orthographic views cannot see whether an object is moving away from itself or in front of us. Why?

Because it doesn't shrink based on distance. So if you draw an object of a fixed size in front of the viewpoint, and at the same time draw an object of the same size far behind the first object, you cannot say that object is the first.

因为两个都是一样的大小,根距离无关。他们不会随着距离而收缩。

 和透视Perspective(有消失点投影)的区别

UI或2D游戏使用正交相机

 和透视Perspective(有消失点投影)的区别
通常我们在unity中制作2D UI,或是2D游戏的时候,就会把Camera的投射选择此项,例如NGUI的UICamera组件,默认的视图就是正交,还有2DTookit,也会把Main Camera的视图选择成正交。

透视Perspective(有消失点投影)

透视视图和我们从眼睛看到的视图是一样的。

例子:远小近大

一个高个子的人站在你面前,他看上去是很高的。

但是如果这个高个子站在100米以外,他甚至还没有你的拇指大。他看上去会随着距离而缩小,但是我们实际上都知道,它依然是个高个子。这种效果叫做透视。

例子中提到的两个物体,第二个物体将会显示地更小,所以我们可以区分哪个是离我们近的物体,那个是离我们远的物体。




来源:https://www.cnblogs.com/zhaoqingqing/archive/2013/09/05/3302484.html

 和透视Perspective(有消失点投影)的区别

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326306050&siteId=291194637