- 最后登录
- 2016-10-1
- 注册时间
- 2013-12-28
- 阅读权限
- 90
- 积分
- 5805
- 纳金币
- 2954
- 精华
- 3
|
最近研究拋物線的東西~~簡單的寫了一些範例跟大家分享一下
將專案包起來放在以下路徑~!請用4.3或以上版本開
http://pan.baidu.com/s/1qW4Q9mW
RunRun2 是拋物線動畫
RunLine 是拋物線軌跡!
我是分開2個檔
主要函式是用
Ax^2 + bx + c來實作的
大家可以修改一下程式中的a,b,c變數跑起來會有不一樣的效果~~
因為是測試用寫了很簡單~~請大家不要見怪阿!!~~
以下是Code- using UnityEngine;
- using System.Collections;
-
- public class RunLine : MonoBehaviour {
- float a = -0.02f;//負數缺口向下正的缺口向上
- float b = 0;
- float c = 100;//頂點會偏移改變;
- public GameObject gg;
- // Use this for initialization
- void Start () {
- //拋物線點
- for (int x = -50; x <= 50; x++)
- {
- Vector3 v3 = test(x);
- Debug.Log(v3);
- Instantiate(gg,v3,Quaternion.identity);
- }
- }
-
- public Vector3 test(float x)
- {
- float y = a * (x * x) + b * x + c;
- Vector3 v2 = new Vector3(x, y, 0);
-
- return v2;
- }
- // Update is called once per frame
- void Update () {
-
-
-
-
-
- }
- }
复制代码- using UnityEngine;
- using System.Collections;
-
- public class RunRun2 : MonoBehaviour {
- //拋物線動畫
- // Use this for initialization
- float a = -0.02f;
- float b = 0;
- float c = 100;//頂點會偏移改變
- public GameObject gg;
- Vector3 vectorEnd = new Vector3(100, 0, 0);
- float beforVector1;
- float time = 0;
- // Use this for initialization
- void Start()
- {
- beforVector1 = this.transform.position.x;
-
- }
-
- public Vector3 test(float x)
- {
- float y = a * (x * x) + b * x + c;
- Vector3 v2 = new Vector3(x, y, 0);
-
- return v2;
- }
-
-
- // Update is called once per frame
- void Update()
- {
-
- if (transform.position.x <= 50)
- {
- Vector3 vector3 = Vector3.right * (50 * Time.deltaTime * 0.5f);
- time += Time.deltaTime;
- Vector3 tmpV3 = transform.position + vector3;
- //transform.position += vector3;
- transform.position = test(tmpV3.x);
- float afterVector1 = this.transform.position.x - beforVector1;
- Debug.Log(time + ":" + afterVector1);
- }
-
-
-
- }
- }
复制代码 |
|