Skip to content

Instantly share code, notes, and snippets.

@davepape
Last active September 19, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepape/9a7e90e11ec4c082606c4258f8105187 to your computer and use it in GitHub Desktop.
Save davepape/9a7e90e11ec4c082606c4258f8105187 to your computer and use it in GitHub Desktop.
// 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