码迷,mamicode.com
首页 > 编程语言 > 详细

Unity Vector3.Slerp使用范例

时间:2017-09-24 22:28:14      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:unit   star   技术   http   print   deb   pre   bsp   com   

 

技术分享

 技术分享技术分享

 

 

 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使用范例

标签:unit   star   技术   http   print   deb   pre   bsp   com   

原文地址:http://www.cnblogs.com/XRTSDUT2008/p/7588642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!