Search Unity

Rigidbody on rotating Platform?

Discussion in 'Physics' started by mangax, Mar 14, 2015.

  1. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    hello , i don't often post new topics , i try best to figure out things my own but this issue really.. no idea how to solve!

    i want to have a cube rigidbody to stay still on rotating circular rigidbody platform and i do not want to use friction and those stuff.

    i've solved this by applying same velocity at cube rigidbody by reading this info from the platform velocity at point. (see pic)
    forcetocenter.jpg

    yet the issue is.. the box always move slowly away from center... which is understandable due to rotation..
    so i tried applying additional force towards platform center in order to maintain it's position and stop it from gliding away.

    so far, it minimized it's moving (Almost stop)..
    but still it keeps Moving slowly!!! i tried many math formulas and still can't stop it in it's place!

    i used this script at the cube:

    Code (CSharp):
    1.  
    2. public class cubetest : MonoBehaviour {
    3.  
    4.     Rigidbody RB;
    5.     Rigidbody theplatform;
    6.     // Use this for initialization
    7.     void Start () {
    8.         RB = GetComponent<Rigidbody>();
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void FixedUpdate () {
    13.    
    14.         if(theplatform==null)return;
    15.  
    16.         var vpoint = RB.position;
    17.         vpoint.y=theplatform.position.y;
    18.  
    19.         var outterVel= theplatform.GetPointVelocity(RB.position);
    20.  
    21.  
    22.         float radius = Vector3.Distance(theplatform.position,vpoint);
    23.        
    24.         float force =    ( (  outterVel.magnitude  ) /  (radius*radius ) );
    25.        
    26.  
    27.         outterVel +=   (theplatform.position-vpoint).normalized   * force      ;
    28.  
    29.  
    30.  
    31.  
    32.         RB.velocity=outterVel;
    33.         RB.angularVelocity=theplatform.angularVelocity * 0.5f;
    34.     }
    35.  
    36.  
    37.     void OnCollisionEnter( Collision col)
    38.     {
    39.         theplatform = col.transform.GetComponent<Rigidbody>();
    40.  
    41.     }
    42. }
    43.  
    any help appreciated! :)
     
  2. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    Physics or kinematic?
     
    Last edited: Apr 15, 2015
  3. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    thanks for help, am really looking for "pure" physics solution that is implemented on fixedupdate.
    i want to keep physics interactions open without resorting to manually adjusting their position.
     
  4. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    okay so it seems i solved the issue :D, which is honestly i didn't expect... just to share what happened..

    it seems the friction was causing the issue,, i didn't even think that it is possible for friction to occur on two surfaces moving together at same speed.. so using physics material with everything zero-ed out solved it.
    with few tweaks in script.. now running perfectly :p
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    you want a pure physics solution, but you don't want to use friction? I don't understand. Friction is exactly the solution you need to stop it moving.

    Failing that, i'd parent it to the platform
     
  6. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    yes i wanted to solve issue using pure physics which means no resorting to using translation/etc
    it's true that friction can aid.. but my target is to have more "predictable" physics..while not losing all of the physics juice!
    more like a character controller for the cube and for other uses in mind.
     
    Last edited: Mar 19, 2015