Created
December 7, 2012 22:01
-
-
Save MatthewMaker/4236872 to your computer and use it in GitHub Desktop.
C# translation of http://u3d.as/content/perflexive-media/floatate/2Fe
This file contains hidden or 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 UnityEngine; | |
| using System.Collections; | |
| public class Floatate1 : MonoBehaviour { | |
| /************************************** | |
| * Copyright (c) 2012, Timothy Thomas * | |
| * Some rights reserved. * | |
| **************************************/ | |
| //converted to C# by Matt "Trip" Maker | |
| public float bobSpeed = 3.0f; //Bob speed | |
| public float bobHeight = 0.5f; //Bob height | |
| public float bobOffset = 0.0f; | |
| public float PrimaryRot = 80.0f; //First axies degrees per second | |
| public float SecondaryRot = 40.0f; //Second axies degrees per second | |
| public float TertiaryRot = 20.0f; //Third axies degrees per second | |
| private float bottom; | |
| //@script AddComponentMenu("Perflexive Media/Floatate") | |
| void Awake () { | |
| if (bobSpeed < 0) { | |
| Debug.LogWarning("Negative object bobSpeed value! May result in undesired behavior. Continuing anyway.", gameObject); | |
| } | |
| if (bobHeight < 0) { | |
| Debug.LogWarning("Negative object bobHeight value! May result in undesired behavior. Continuing anyway.", gameObject); | |
| } | |
| bottom = transform.position.y; | |
| } | |
| void Update () { | |
| transform.Rotate(new Vector3(0, PrimaryRot, 0) * Time.deltaTime, Space.World); | |
| transform.Rotate(new Vector3(SecondaryRot, 0, 0) * Time.deltaTime, Space.Self); | |
| transform.Rotate(new Vector3(0, 0, TertiaryRot) * Time.deltaTime, Space.Self); | |
| transform.position = new Vector3(transform.position.x, bottom + (((Mathf.Cos((Time.time + bobOffset) * bobSpeed) + 1) / 2 ) * bobHeight), transform.position.z); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment