Last active
September 19, 2018 20:10
-
-
Save davepape/9a7e90e11ec4c082606c4258f8105187 to your computer and use it in GitHub Desktop.
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
// Minimal Unity3d example of moving an object in a circle | |
// Script determines a current angle, then computes an X & Y for that angle using cos & sin | |
// Object is placed at the computed X,Y by setting the "localPosition" attribute of its transform | |
// Script uses 2 public variables so that you can control the size of the circle and how fast it moves | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class circle1 : MonoBehaviour { | |
public float radius = 5f; | |
public float speed = 1f; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
float angle = Time.time * speed; | |
float x = Mathf.Cos(angle) * radius; | |
float y = Mathf.Sin(angle) * radius; | |
transform.localPosition = new Vector3(x, y, 0f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment