Unity physics engine Implementation uniform circular motions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.