Last active
March 8, 2017 12:52
-
-
Save arunkarnann/456dc8a7b865c7ac5b95fc725e92da71 to your computer and use it in GitHub Desktop.
Birds flying in sine wave form Unity3d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class FlyBirds : MonoBehaviour { | |
Vector3 firstPos; | |
[SerializeField] | |
Vector3 lastPos; | |
[SerializeField] | |
float xSpeed=5f; | |
/// <summary> | |
/// The distance at which the object should move up and down | |
/// </summary> | |
[SerializeField] | |
float yLimit=50f; | |
[SerializeField] | |
float cosineMultiplier=2f; | |
float elapsedTime; | |
///Reduce to increase the wave length in y axis | |
float cosineValue=0.5f; | |
void Update () { | |
elapsedTime += Time.deltaTime; | |
cosineValue = Mathf.Cos( Mathf.PI * elapsedTime * cosineMultiplier ) ; | |
Vector3 newPosition = new Vector3(lastPos.x ,(lastPos.y + yLimit) * cosineValue,lastPos.z); | |
transform.position = Vector3.MoveTowards (transform.position, newPosition, xSpeed * Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment