sine曲線の前方移動

3360 ワード

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;

    }

}