Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CircularMovement : MonoBehaviour {
  5.  
  6. float timeCounter = 0f;
  7. public float rotationRadius; //multiplied with sin and cos
  8. public Vector3 rotationCenter; //multiplied with position.x and y
  9. public float rotationSpeed = 1;
  10.  
  11. void Awake()
  12. {
  13. rotationCenter = transform.parent.position;
  14. }
  15.  
  16. void Update () {
  17. timeCounter += Time.deltaTime * rotationSpeed;
  18. //3rd grade highschool math. sin and cos make the object move circularly.
  19. float x = Mathf.Cos(timeCounter) * rotationRadius;
  20. float y = Mathf.Sin(timeCounter) * rotationRadius;
  21. float z = -1;
  22.  
  23. transform.position = new Vector3(x + rotationCenter.x, y + rotationCenter.y, z);
  24.  
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement