sine曲线向前运动

using UnityEngine;
using System.Collections;

public class sineWork : MonoBehaviour {

    float verticalSpeed = 5.0f;                    //Vertical speed
    float verticalDistance = 6.0f;                //Vertical distance
    
    float horizontalSpeed  = 2;                    //Horizontal speed
    
    float offset = 0.0f;                        //Vertical offset
    float originalPos = 0;                        //Original y position
    
    Vector3 nextPos = new Vector3();            //Stores the next position
    Vector3 startingPos;    

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {

            //Get current position
            nextPos = this.transform.position;
            
            //Calculate new vertical position
            offset = (1 + Mathf.Sin(Time.time * verticalSpeed)) * verticalDistance / 2.0f;
            nextPos.y = originalPos + offset;
            
            //Calculate new horizontal position
            nextPos.x -= horizontalSpeed * Time.deltaTime;
            
            //Apply new position
            this.transform.position = nextPos;
    }
}

 

posted @ 2014-05-22 15:52  softimagewht  阅读(453)  评论(0编辑  收藏  举报