Summary
This article focuses on how to implement uniform circular motions with the unity physics engine.
Objective
First, we can use unity Api,transform.rotatearound to implement uniform circular motions. But this implementation, I think not enjoyable, because you just understand an API, and did not learn any other knowledge. Take a little bit of interesting stuff.
Physical knowledge
1. Definition:
The motion is called "Uniform circular Motions", also known as "uniform rate circumferential motion", if the arc length is equal in any equal time. Because the velocity of the object is constant in the circumferential motion, but the speed direction changes at any time. So the line speed of uniform circular motions is changing all the time.
2. Basic formula:
V (line speed) =δs/δt=2πr/t=ωr=2πrn (s for arc length, T for time, R for RADIUS, N for Speed)
Ω (angular velocity) =δθ/δt=2π/t=2πn (θ denotes angle or radian)
T (cycle) =2πr/v=2π/ω
Fn (centripetal force) =mrω^2=mv^2/r=mr4π^2/t^2=mr4π^2n^2
For the sake of convenience, we use the line speed V, radius r, Mass m, to calculate the centripetal force. F=m*v*v/r
Source:
Using unityengine;using System.collections;public class Circle:monobehaviour {public Vector3 linerspeed;public Vector3 circledot;private float radius;private rigidbody body;private float speed;private float omga;//Use this for initializatio Nvoid Start () {body=gameobject.getcomponent<rigidbody> (); body.velocity = Linerspeed;radius = (CircleDot- gameObject.transform.position). Magnitude;speed = Linerspeed.magnitude;omga = Speed *speed/radius;} Update is called once per framevoid update () {//debug.log (body.velocity);} void Fixedupdate () {Vector3 fp = circledot-gameobject.transform.position;//centripetal vector, but at this time the vector mode is incorrect FP = fp.normalized * Body.mas S * omga;//to correct the modulus body of the vector. Addforce (Fp,forcemode.force);}}
Warm tips:
Circledot: Around which point do uniform circular motions.
Linerspeed: The line speed of the uniform circular motions.
1.AddForce need to use Forcemode.force mode, do not use impulse mode. The impulse mode increases the centripetal force effect, which leads to more closer to the center.
2. use space in exchange for time to save some of the results for reuse in the next frame.
3. using the physical engine consumes more performance , but you can learn more, and perhaps even better methods, here.
Unity physics engine Implementation uniform circular motions