Skip to content

Instantly share code, notes, and snippets.

@trentrand
Created August 1, 2016 23:11
Show Gist options
  • Save trentrand/1c06d177b95a4678b38aa0d740521349 to your computer and use it in GitHub Desktop.
Save trentrand/1c06d177b95a4678b38aa0d740521349 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class BubbleBobber : MonoBehaviour {
private float timer = 0.0f;
float bobbingSpeed = 0.18f;
float bobbingAmount = 0.2f;
float midpoint = 2.0f;
void Update () {
float waveslice = 0.0f;
Vector3 cSharpConversion = transform.localPosition;
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
if (waveslice != 0) {
float translateChange = waveslice * bobbingAmount;
float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0f, 1.0f);
translateChange = totalAxes * translateChange;
cSharpConversion.y = midpoint + translateChange;
}
else {
cSharpConversion.y = midpoint;
}
transform.localPosition = cSharpConversion;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment