码迷,mamicode.com
首页 > 其他好文 > 详细

抛物线

时间:2015-02-04 14:32:25      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

 1 using UnityEngine;
 2 
 3 using System.Collections;
 4 
 5 public class ProjectileTest : MonoBehaviour
 6 {
 7 
 8     public GameObject target;
 9 
10     public float speed = 10;
11 
12     private float distanceToTarget;
13 
14     private bool move = true;
15 
16     void Start()
17     {
18 
19         distanceToTarget = Vector3.Distance(this.transform.position, target.transform.position);
20 
21         StartCoroutine(Shoot());
22 
23     }
24 
25     IEnumerator Shoot()
26     {
27 
28         while (move)
29         {
30 
31             Vector3 targetPos = target.transform.position;
32 
33             this.transform.LookAt(targetPos);
34 
35             float angle = Mathf.Min(1, Vector3.Distance(this.transform.position, targetPos) / distanceToTarget) * 45;
36 
37             this.transform.rotation = this.transform.rotation * Quaternion.Euler(Mathf.Clamp(-angle, -42, 42), 0, 0);
38 
39             float currentDist = Vector3.Distance(this.transform.position, target.transform.position);
40 
41             print("“currentDist”" + currentDist);
42 
43             if (currentDist < 0.5f)
44 
45                 move = false;
46 
47             this.transform.Translate(Vector3.forward * Mathf.Min(speed * Time.deltaTime, currentDist));
48 
49             yield return null;
50 
51         }
52 
53     }
54 
55 }

 

抛物线

标签:

原文地址:http://www.cnblogs.com/ssw-men/p/4272149.html

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