unity3d 怎么模拟抛物线运动
答案:2 悬赏:50 手机版
解决时间 2021-12-31 06:32
- 提问者网友:轻浮
- 2021-12-30 16:08
unity3d 怎么模拟抛物线运动
最佳答案
- 五星知识达人网友:白昼之月
- 2021-12-30 16:42
这个很简单的啊,你去搜索一个插件(itween,hotween,dotween)这三个插件都可以很简单的实现你说的功能,不会用插件的话去百度下,很多教程的
全部回答
- 1楼网友:动情书生
- 2021-12-30 18:03
把这个脚本挂在一个cube上,然后把另一个cube拖到target上,把这两个物体之间有一段距离,然后运行,就看到效果了
using unityengine;
using system.collections;
public class projectiletest : monobehaviour
{
public gameobject target;
public float speed = 10;
private float distancetotarget;
private bool move = true;
void start ()
{
distancetotarget = vector3.distance (this.transform.position, target.transform.position);
startcoroutine (shoot ());
}
ienumerator shoot ()
{
while (move) {
vector3 targetpos = target.transform.position;
this.transform.lookat (targetpos);
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);
print ("currentdist" + currentdist);
if (currentdist < 0.5f)
move = false;
this.transform.translate (vector3.forward * mathf.min (speed * time.deltatime, currentdist));
yield return null;
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯