Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CircularMovement : MonoBehaviour {
- float timeCounter = 0f;
- public float rotationRadius; //multiplied with sin and cos
- public Vector3 rotationCenter; //multiplied with position.x and y
- public float rotationSpeed = 1;
- void Awake()
- {
- rotationCenter = transform.parent.position;
- }
- void Update () {
- timeCounter += Time.deltaTime * rotationSpeed;
- //3rd grade highschool math. sin and cos make the object move circularly.
- float x = Mathf.Cos(timeCounter) * rotationRadius;
- float y = Mathf.Sin(timeCounter) * rotationRadius;
- float z = -1;
- transform.position = new Vector3(x + rotationCenter.x, y + rotationCenter.y, z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement