Unity Vector3.Slerp使用范例

Posted 童小童

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity Vector3.Slerp使用范例相关的知识,希望对你有一定的参考价值。

 

 

 

 

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class TestSlerp : MonoBehaviour
 6 {
 7     public Transform a;
 8     public Transform b;
 9 
10     void Start()
11     {
12 
13     }
14     bool kaishi = false;
15     float T;
16     void Update()
17     {
18         if (Input.GetKeyDown(KeyCode.S))
19         {
20             kaishi = true;
21             T = Time.time;
22             print(Time.time + " SSSSSSSSSSS  " + T);
23 
24         }
25         if (kaishi)
26         { 
27             Debug.DrawLine(Vector3.zero, new Vector3(10, 10, 10), Color.red);
28             //for (int i=0;i<11;++i)
29             //{
30             Vector3 center = (a.position + b.position) * 0.5f;
31             center -= new Vector3(0, 2, 0);
32             Vector3 temp1 = a.position - center;
33             Vector3 temp2 = b.position - center;
34             print(Time.time + "   " + T);
35             Vector3 c = Vector3.Slerp(temp1, temp2, (Time.time-T) * 0.1f);
36 
37             c += center;
38             transform.position = c;
39             //Debug.DrawRay(center, c, Color.red);
40             //Debug.DrawRay(Vector3.zero, c, Color.red);
41             Debug.DrawLine(center, c, Color.blue);
42             Debug.DrawLine(Vector3.zero, c, Color.blue);
43 
44             // print(i);
45         }
46     }
47 }

最终效果如下:

 

 

 

 修改如下:

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class TestSlerp : MonoBehaviour {
 6     public Transform a;
 7     public Transform b;
 8     void Start () {
 9        
10     }
11     void Update () {
12          Debug.DrawLine(Vector3.zero,new Vector3(10,10,10),Color.red);
13         for (int i=0;i<11;++i)
14         {
15             Vector3 center = (a.position + b.position) *0.5f;
16             center -= new Vector3(0,2,0);
17             Vector3 temp1 =a.position - center;
18             Vector3 temp2 =b.position - center;
19             Vector3 c = Vector3.Slerp(temp1, temp2, i * 0.1f);
20             Debug.DrawLine(center, c, Color.blue);
21             Debug.DrawLine(Vector3.zero, c, Color.blue);
22         }
23     }
24 }

效果如下:

 

 更多可参考:http://www.manew.com/thread-43314-1-1.html

以上是关于Unity Vector3.Slerp使用范例的主要内容,如果未能解决你的问题,请参考以下文章

Unity 物体轨迹移动

Unity3D的NGUI插件导入工程后提示错误:UnityEngine.QualitySettings、 GetQualityLevel

python多线程模块thread使用范例的代码

python threading超线程使用简单范例的代码

OpenACC 书上的范例代码(Jacobi 迭代),part 2

Shell中的${ }###%%%使用范例