Parametic equation for circular motion not giving desired effect
I have tried to use the parametric equations for circular motion to move an object around a circle. x(t) = A*cos(2pi * t), y(t) = B*sin(2pi *t)
The object moves in a circle when I run the code, but the orbit of the object moves downwards slightly with every rotation meaning it eventually goes off the screen. Obviously I do not want this to occur and I was it to revolve around the same point in space. I have worked out that this was due to gravity being set to 1 on the rigidbody. However when I set it to 0, it only completes a half circle and then stops.
Here is my code:
using UnityEngine; using System.Collections;
public class Parametric : MonoBehaviour {
public float loadtime;
float xpos;
float ypos;
Vector2 positionVector;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
Debug.Log (Time.timeSinceLevelLoad);
loadtime = Time.timeSinceLevelLoad;
xpos = Mathf.Cos (2 * Mathf.PI * loadtime);
ypos = Mathf.Sin (2 * Mathf.PI * loadtime);
positionVector = this.transform.rigidbody2D.position;
positionVector.x = xpos;
positionVector.y = ypos;
this.transform.rigidbody2D.position = positionVector;
}
}
Comment