I want to create 2d flying object that can waving up and down and move forward. I had put my object with position.y = 7 on the scene, but when i start the game, the object will BLINK to position.y = 0 and start amplitude up and down. Can anyone help me to fix this code so my object will start amplitude by its current y position? Below is the codes i put to my object:
using UnityEngine;
using System.Collections;
public class BirdMovement : MonoBehaviour {
public float horizontalSpeed;
public float verticalSpeed;
public float amplitude;
private Vector3 tempPosition;
// Use this for initialization
void Start () {
tempPosition = transform.position;
}
// Update is called once per frames
void Update () {
tempPosition.x += horizontalSpeed;
tempPosition.y = Mathf.Sin (Time.realtimeSinceStartup * verticalSpeed) * amplitude;
transform.position = tempPosition;
}
}