欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實(shí)現(xiàn)物體弧線運(yùn)動(dòng)到規(guī)定的坐標(biāo)

 更新時(shí)間:2020年06月21日 17:01:16   作者:天人合一moonlight  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)物體以弧線的形式運(yùn)動(dòng)到規(guī)定的坐標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)以弧線的形式運(yùn)動(dòng)到規(guī)定坐標(biāo)的具體代碼,供大家參考,具體內(nèi)容如下

1、u3d場(chǎng)景的設(shè)置

2、 Run 腳本

using UnityEngine;
using System.Collections;
 
public class Run : MonoBehaviour
{
 public GameObject target; //要到達(dá)的目標(biāo)
 public float speed = 10; //速度
 private float distanceToTarget; //兩者之間的距離
 private bool move = true; 
 
 void Start()
 {
 //計(jì)算兩者之間的距離
 distanceToTarget = Vector3.Distance(this.transform.position, target.transform.position); 
 StartCoroutine(StartShoot());
 }
 
 IEnumerator StartShoot()
 {
 
 while (move)
 {
 Vector3 targetPos = target.transform.position;
 
 //讓始終它朝著目標(biāo)
 this.transform.LookAt(targetPos);
 
 //計(jì)算弧線中的夾角
 float angle = Mathf.Min(1, Vector3.Distance(this.transform.position, targetPos) / distanceToTarget) * 45;
 this.transform.rotation = this.transform.rotation * Quaternion.Euler(Mathf.Clamp(-angle, -42, 42), 0, 0);
 float currentDist = Vector3.Distance(this.transform.position, target.transform.position);
 if (currentDist < 0.5f)
 move = true;
 this.transform.Translate(Vector3.forward * Mathf.Min(speed * Time.deltaTime, currentDist));
 yield return null;
 }
 }
 
 
}

3、運(yùn)行結(jié)果

重合到一起后,拖動(dòng)Start的小球,松手后又會(huì)重合。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論