Skip to content

Instantly share code, notes, and snippets.

@neuman
Created October 9, 2015 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuman/1c2315c9bb7d9b936682 to your computer and use it in GitHub Desktop.
Save neuman/1c2315c9bb7d9b936682 to your computer and use it in GitHub Desktop.
Unity Hovering Animation Behavior
using UnityEngine;
using System.Collections;
using System;
public class HoverBob : MonoBehaviour {
float originalY;
public float floatSpeed = 1;
public float floatStrength = 1;
void Start()
{
this.originalY = this.transform.position.y;
}
void Update()
{
transform.position = new Vector3(transform.position.x,
originalY + ((float)Math.Sin(Time.time*floatSpeed) * floatStrength),
transform.position.z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment