Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Dragonrider-Liu · Mar 20, 2018 at 02:28 PM · physicsscript.physics2d2d-physics2d-gameplay

Failed to achieve uniform circle movement with rigidbody2D.

Hello,

I try to make rigidbody2Ds to do uniform movement based on the function F=mv^2/r, but the movement always become not uniform or totally irregular.

There are at least 3 modes are observed. The common thing is that the radius (distance between the rigidbody2D) changes, in different pattern. And their codes for the physics2D are run in different parts.

First one (physics run in coroutine), the rigidbody2Ds rotate around the center with the radius cycling between 0.5 and 1, I have to admit that this mode is interesting and lovely, it looks sort of like some dancers dance around bonfire (center), and some time dance in a closer distance, some time in a larger circle. Hope you can imagine that. Though it's beautiful, it is not the movement I want.

Second (physics run in update() ), the rigidbody2Ds rotate around for a short while (may be 0.5s?), and then they just fly away...

Third (physics run in FixedUpdate() ), I create a test project, use the red dots. The radius become smaller, though it looks fine in naked eye. The radius decrease from 1 to about 0.7, and it seems to increase very very slowly after that (this may be a little like the first mode? just far slower?). And after a long time (about 3min), the dots don't spread equally around the circle.(Fig2.)

debug.Log the distance of dots and center fig1. initial value and several seconds later

alt text

fig2. the distribution of dots around the centers.

alt text

Here's the code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Player_Controller : MonoBehaviour
 {
 
     public GameObject Test;                 //the GameObject for test, the red dot.
     public List<GameObject> TestObject;      // to hold the red dots to control their movement.
     public List<Vector3> Center;             // to hold the centers surrounded by the dots.
     private Vector3 center;                  // will be randomized in each cycle.
     private Vector3 Posi;                      //hold the initial position of the dots.
     private static float radian=Mathf.PI/3;  // radian angle to spread the dots
 
     void Start()
     {
         Quaternion Rotation = Quaternion.identity;
         for (int i = 0; i < 4; i++)
         {
             center = new Vector3(Random.Range(-12f, 12f), Random.Range(-4.4f, 4.4f), 0);     //get the center
             for (int j = 0; j < 6; j++)
             {
                 // Decide the position of the dot on the circle
                 float Angle = radian * j ; 
                 Posi=new Vector3(center.x+Mathf.Cos(Angle),center.y+Mathf.Sin(Angle),0);
                 
                 // Instantiate the dot and give the initial velocity in tangential direction.
                 GameObject tmpGameObject = Instantiate(Test, Posi, Rotation) as GameObject;
                 TestObject.Add(tmpGameObject);             // store the dot into list for further control.
                 Center.Add(center);                      //store the coordinate of this dot's center.
                 tmpGameObject.GetComponent<Rigidbody2D>().velocity =new Vector2(center.y - tmpGameObject.transform.position.y, tmpGameObject.transform.position.x - center.x).normalized *2.0f;
             }
         }
     }
 
     void FixedUpdate()
     {
             foreach (var dot in TestObject)
             {
                 if (dot != null)
                 {
                     Rigidbody2D missileRigidbody2D = dot.GetComponent<Rigidbody2D>();
                     
                     //Get this dot's center
                     int i = TestObject.IndexOf(dot);
                     Vector3 centerVector3 = Center[i];
 
                     //Base on F=mv^2/r, here, F is the magnitude of the force.
                     float F = missileRigidbody2D.mass * missileRigidbody2D.velocity.sqrMagnitude / Vector3.Distance(dot.transform.position, centerVector3);
                     missileRigidbody2D.AddForce(new Vector2(centerVector3.x - dot.transform.position.x, centerVector3.y - dot.transform.position.y).normalized * F, ForceMode2D.Force);
                     Debug.Log(Vector3.Distance(dot.transform.position, centerVector3));
                 }
             }
         }
 }
 

fig2.jpg (54.9 kB)
fig1.jpg (82.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

196 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics of boxes and blocks in 2d 0 Answers

Is there joint physics example asset? 0 Answers

How to make flips, backflips like in game Backflip madness 2 Answers

stick-figure piercing 0 Answers

How do I get a ball to bounce inside of a circle? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges