首页 > 编程语言 > 详细

Unity之一天一个技术点(十六)---狙击镜呼吸效果

时间:2015-02-05 11:18:37      阅读:402      评论:0      收藏:0      [点我收藏+]

我们正在做一个狙击游戏,然后要模仿一个狙击镜打开时候呼吸效果,也就是狙击镜会上下左右平缓位移,我参考网上的脚本又更改了一下,你可以直接挂在你的镜头上,然后屏幕中间放一个瞄准镜,就能看到很酷的效果~

 public void Noise()
    {

noisedeltaX += ((((Mathf.Cos(Time.time) * Random.Range(-nosieMaxRange, nosieMaxRange) / 5f) * nosieMaxSpeed) - noisedeltaX) / 100);
noisedeltaY += ((((Mathf.Sin(Time.time) * Random.Range(-nosieMaxRange, nosieMaxRange) / 5f) * nosieMaxSpeed) - noisedeltaY) / 100);




        rotationXtemp += (noisedeltaX * breathHolderVal);
        rotationYtemp += (noisedeltaY * breathHolderVal);
        rotationX += ((rotationXtemp - rotationX) / 3) ;
        rotationY += ((rotationYtemp - rotationY) / 3) ;


        if (rotationX >= 360)
        {
            rotationX = 0;
            rotationXtemp = 0;
        }
        if (rotationX <= -360)
        {
            rotationX = 0;
            rotationXtemp = 0;
        }


         rotationX = ClampAngle(rotationX, -180, 180);
         rotationY = ClampAngle(rotationY, -60, 60);
         rotationYtemp = ClampAngle(rotationYtemp, -60, 60);
        


        Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.left);
        Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.forward);


        transform.localRotation = transform.localRotation * xQuaternion * yQuaternion;


    
    }


    static float ClampAngle(float angle, float min, float max)
    {
        if (angle <= -360.0f)
            angle += 360.0f;


        if (angle >= 360.0f)
            angle -= 360.0f;


        return Mathf.Clamp(angle, min, max);
    }


Unity之一天一个技术点(十六)---狙击镜呼吸效果

原文:http://blog.csdn.net/myk7694503/article/details/43524779

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!