- Home /
Simulate perfect circular motion with addforce
Hi, I,m trying to simulate circular motion in unity using different value of force. However, I can't actually perform a perfect circular motion using the AddForce() function. Like, when the velocity of an object is 10ms^-1 and radius from center is 10m, it should have a perfect circular motion with a centripetal force of 10ms^-2, but when it start moving it just lost control and never keep in a perfect circle track! This is my work: A rocket and a planet are initially placed in x=0, as shown: The rocket given an initial speed in y axis:
void Start () {
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(0, speed);
}
The planet have a constant force pulling the rocket to it:
//Fixed Timestep=0.02
void FixedUpdate () {
// transform.position is position of a "planet"
direction = (transform.position-rocket.transform.position).normalized;
//rocket is a object circulating the planet with an initial velocity
rocket.GetComponent<Rigidbody2D>().AddForce(direction*force)
}
I want to simulating the motion in different variable, so I don't want to hard code it by changing it's position. How can I do this with AddForce or other method? Thank You.