-
-
Save belzecue/4b402b3ce0f753f00604d6af2c244737 to your computer and use it in GitHub Desktop.
Various motion exmaples with sin & cos
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
| #define _Example4 | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class MotionLogic : MonoBehaviour | |
| { | |
| public float speed = 1.0f; | |
| [Range(0.5f, 3.5f)] | |
| public float radius = 2.0f; | |
| #if _Example2 | |
| [Range(-6.28f, 6.28f)] | |
| public float yAxisOffset = 2.5f; | |
| #endif | |
| #if _Example3 || _Example4 | |
| [Range(0.5f, 15.0f)] | |
| public float frequency = 10.0f; | |
| #endif | |
| private void Update() | |
| { | |
| float inputValue = Time.timeSinceLevelLoad * speed; | |
| #if _Example1 | |
| transform.position = new Vector2(Mathf.Sin(inputValue) * radius, Mathf.Cos(inputValue) * radius); | |
| #endif | |
| #if _Example2 | |
| transform.position = new Vector2(Mathf.Sin(inputValue) * radius, Mathf.Cos(inputValue + yAxisOffset) * radius); | |
| #endif | |
| #if _Example3 | |
| transform.position = new Vector2(Mathf.Sin(inputValue) * (radius + Mathf.Cos(inputValue * frequency)), Mathf.Cos(inputValue) * (radius + Mathf.Cos(inputValue * frequency))); | |
| #endif | |
| #if _Example4 | |
| transform.position = new Vector2(Mathf.Sin(inputValue) * (radius + Mathf.Cos(inputValue + Mathf.Sin(inputValue * frequency))), Mathf.Cos(inputValue) * (radius + Mathf.Cos(inputValue + Mathf.Cos(inputValue * frequency)))); | |
| #endif | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment