Unity3d: how to apply a vortex like force to objects?










2














I would like to simulate a vortex like force to a "bunch" of objects in my scene.



How can I do in Unity ?



Thanks










share|improve this question





















  • what kind of objects are they? What type of space you operating in (2D or 3D)?
    – Confused
    Nov 12 at 13:13










  • Objects are sphere, in a 3d environment. What i need to simulate is an hand that move balls (spheres) into a vase
    – stighy
    Nov 12 at 14:25















2














I would like to simulate a vortex like force to a "bunch" of objects in my scene.



How can I do in Unity ?



Thanks










share|improve this question





















  • what kind of objects are they? What type of space you operating in (2D or 3D)?
    – Confused
    Nov 12 at 13:13










  • Objects are sphere, in a 3d environment. What i need to simulate is an hand that move balls (spheres) into a vase
    – stighy
    Nov 12 at 14:25













2












2








2


1





I would like to simulate a vortex like force to a "bunch" of objects in my scene.



How can I do in Unity ?



Thanks










share|improve this question













I would like to simulate a vortex like force to a "bunch" of objects in my scene.



How can I do in Unity ?



Thanks







unity3d






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 13:01









stighy

2,8081974127




2,8081974127











  • what kind of objects are they? What type of space you operating in (2D or 3D)?
    – Confused
    Nov 12 at 13:13










  • Objects are sphere, in a 3d environment. What i need to simulate is an hand that move balls (spheres) into a vase
    – stighy
    Nov 12 at 14:25
















  • what kind of objects are they? What type of space you operating in (2D or 3D)?
    – Confused
    Nov 12 at 13:13










  • Objects are sphere, in a 3d environment. What i need to simulate is an hand that move balls (spheres) into a vase
    – stighy
    Nov 12 at 14:25















what kind of objects are they? What type of space you operating in (2D or 3D)?
– Confused
Nov 12 at 13:13




what kind of objects are they? What type of space you operating in (2D or 3D)?
– Confused
Nov 12 at 13:13












Objects are sphere, in a 3d environment. What i need to simulate is an hand that move balls (spheres) into a vase
– stighy
Nov 12 at 14:25




Objects are sphere, in a 3d environment. What i need to simulate is an hand that move balls (spheres) into a vase
– stighy
Nov 12 at 14:25












2 Answers
2






active

oldest

votes


















1














Circular motion:



 float angle =0;
float speed=(2*Mathf.PI)/5 //2*PI in degress is 360, so you get 5 seconds to complete a circle
float radius=5;
void Update()

angle += speed*Time.deltaTime; //if you want to switch direction, use -= instead of +=
x = Mathf.Cos(angle)*radius;
y = Mathf.Sin(angle)*radius;



where the center of your circle is the center of your vortex.



Of course:



  • If you want multiple objects with diferent distance from vortex's

    center you have to play with your radius variable (i would add a

    Random.Range(minDistance, maxDistance))


  • If you want diferent speeds you can randomize/change the speed.


  • Randomize/change your x/y if you don't want a perfect circle

Hope i was clear enought.






share|improve this answer






























    1














    If you are using the physics system, there's two parts to this. Applying the vortex force, and getting the nice swirling effect. To apply the vortex force you can just loop over the rigidbodies and apply the force. To make the swirl look like a proper vortex swirl, you need to start the objects off with a tangential velocity that you can figure out using the vector cross product.



    public float VortexStrength = 1000f;

    public float SwirlStrength = 5f;

    void Start ()
    foreach(GameObject g in RigidBodies)
    //to get them nice and swirly, use the perpendicular to the direction to the vortex
    Vector3 direction = Vortex.transform.position - g.transform.position;
    var tangent = Vector3.Cross(direction, Vector3.up).normalized * SwirlStrength;
    g.GetComponent<Rigidbody>().velocity = tangent;



    void Update()
    //apply the vortex force
    foreach(GameObject g in RigidBodies)
    //force them toward the center
    Vector3 direction = Vortex.transform.position - g.transform.position;
    g.GetComponent<Rigidbody>().AddForce(direction.normalized * Time.deltaTime * VortexStrength);







    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262748%2funity3d-how-to-apply-a-vortex-like-force-to-objects%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Circular motion:



       float angle =0;
      float speed=(2*Mathf.PI)/5 //2*PI in degress is 360, so you get 5 seconds to complete a circle
      float radius=5;
      void Update()

      angle += speed*Time.deltaTime; //if you want to switch direction, use -= instead of +=
      x = Mathf.Cos(angle)*radius;
      y = Mathf.Sin(angle)*radius;



      where the center of your circle is the center of your vortex.



      Of course:



      • If you want multiple objects with diferent distance from vortex's

        center you have to play with your radius variable (i would add a

        Random.Range(minDistance, maxDistance))


      • If you want diferent speeds you can randomize/change the speed.


      • Randomize/change your x/y if you don't want a perfect circle

      Hope i was clear enought.






      share|improve this answer



























        1














        Circular motion:



         float angle =0;
        float speed=(2*Mathf.PI)/5 //2*PI in degress is 360, so you get 5 seconds to complete a circle
        float radius=5;
        void Update()

        angle += speed*Time.deltaTime; //if you want to switch direction, use -= instead of +=
        x = Mathf.Cos(angle)*radius;
        y = Mathf.Sin(angle)*radius;



        where the center of your circle is the center of your vortex.



        Of course:



        • If you want multiple objects with diferent distance from vortex's

          center you have to play with your radius variable (i would add a

          Random.Range(minDistance, maxDistance))


        • If you want diferent speeds you can randomize/change the speed.


        • Randomize/change your x/y if you don't want a perfect circle

        Hope i was clear enought.






        share|improve this answer

























          1












          1








          1






          Circular motion:



           float angle =0;
          float speed=(2*Mathf.PI)/5 //2*PI in degress is 360, so you get 5 seconds to complete a circle
          float radius=5;
          void Update()

          angle += speed*Time.deltaTime; //if you want to switch direction, use -= instead of +=
          x = Mathf.Cos(angle)*radius;
          y = Mathf.Sin(angle)*radius;



          where the center of your circle is the center of your vortex.



          Of course:



          • If you want multiple objects with diferent distance from vortex's

            center you have to play with your radius variable (i would add a

            Random.Range(minDistance, maxDistance))


          • If you want diferent speeds you can randomize/change the speed.


          • Randomize/change your x/y if you don't want a perfect circle

          Hope i was clear enought.






          share|improve this answer














          Circular motion:



           float angle =0;
          float speed=(2*Mathf.PI)/5 //2*PI in degress is 360, so you get 5 seconds to complete a circle
          float radius=5;
          void Update()

          angle += speed*Time.deltaTime; //if you want to switch direction, use -= instead of +=
          x = Mathf.Cos(angle)*radius;
          y = Mathf.Sin(angle)*radius;



          where the center of your circle is the center of your vortex.



          Of course:



          • If you want multiple objects with diferent distance from vortex's

            center you have to play with your radius variable (i would add a

            Random.Range(minDistance, maxDistance))


          • If you want diferent speeds you can randomize/change the speed.


          • Randomize/change your x/y if you don't want a perfect circle

          Hope i was clear enought.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 16:37

























          answered Nov 12 at 16:30









          victor dabija

          5069




          5069























              1














              If you are using the physics system, there's two parts to this. Applying the vortex force, and getting the nice swirling effect. To apply the vortex force you can just loop over the rigidbodies and apply the force. To make the swirl look like a proper vortex swirl, you need to start the objects off with a tangential velocity that you can figure out using the vector cross product.



              public float VortexStrength = 1000f;

              public float SwirlStrength = 5f;

              void Start ()
              foreach(GameObject g in RigidBodies)
              //to get them nice and swirly, use the perpendicular to the direction to the vortex
              Vector3 direction = Vortex.transform.position - g.transform.position;
              var tangent = Vector3.Cross(direction, Vector3.up).normalized * SwirlStrength;
              g.GetComponent<Rigidbody>().velocity = tangent;



              void Update()
              //apply the vortex force
              foreach(GameObject g in RigidBodies)
              //force them toward the center
              Vector3 direction = Vortex.transform.position - g.transform.position;
              g.GetComponent<Rigidbody>().AddForce(direction.normalized * Time.deltaTime * VortexStrength);







              share|improve this answer

























                1














                If you are using the physics system, there's two parts to this. Applying the vortex force, and getting the nice swirling effect. To apply the vortex force you can just loop over the rigidbodies and apply the force. To make the swirl look like a proper vortex swirl, you need to start the objects off with a tangential velocity that you can figure out using the vector cross product.



                public float VortexStrength = 1000f;

                public float SwirlStrength = 5f;

                void Start ()
                foreach(GameObject g in RigidBodies)
                //to get them nice and swirly, use the perpendicular to the direction to the vortex
                Vector3 direction = Vortex.transform.position - g.transform.position;
                var tangent = Vector3.Cross(direction, Vector3.up).normalized * SwirlStrength;
                g.GetComponent<Rigidbody>().velocity = tangent;



                void Update()
                //apply the vortex force
                foreach(GameObject g in RigidBodies)
                //force them toward the center
                Vector3 direction = Vortex.transform.position - g.transform.position;
                g.GetComponent<Rigidbody>().AddForce(direction.normalized * Time.deltaTime * VortexStrength);







                share|improve this answer























                  1












                  1








                  1






                  If you are using the physics system, there's two parts to this. Applying the vortex force, and getting the nice swirling effect. To apply the vortex force you can just loop over the rigidbodies and apply the force. To make the swirl look like a proper vortex swirl, you need to start the objects off with a tangential velocity that you can figure out using the vector cross product.



                  public float VortexStrength = 1000f;

                  public float SwirlStrength = 5f;

                  void Start ()
                  foreach(GameObject g in RigidBodies)
                  //to get them nice and swirly, use the perpendicular to the direction to the vortex
                  Vector3 direction = Vortex.transform.position - g.transform.position;
                  var tangent = Vector3.Cross(direction, Vector3.up).normalized * SwirlStrength;
                  g.GetComponent<Rigidbody>().velocity = tangent;



                  void Update()
                  //apply the vortex force
                  foreach(GameObject g in RigidBodies)
                  //force them toward the center
                  Vector3 direction = Vortex.transform.position - g.transform.position;
                  g.GetComponent<Rigidbody>().AddForce(direction.normalized * Time.deltaTime * VortexStrength);







                  share|improve this answer












                  If you are using the physics system, there's two parts to this. Applying the vortex force, and getting the nice swirling effect. To apply the vortex force you can just loop over the rigidbodies and apply the force. To make the swirl look like a proper vortex swirl, you need to start the objects off with a tangential velocity that you can figure out using the vector cross product.



                  public float VortexStrength = 1000f;

                  public float SwirlStrength = 5f;

                  void Start ()
                  foreach(GameObject g in RigidBodies)
                  //to get them nice and swirly, use the perpendicular to the direction to the vortex
                  Vector3 direction = Vortex.transform.position - g.transform.position;
                  var tangent = Vector3.Cross(direction, Vector3.up).normalized * SwirlStrength;
                  g.GetComponent<Rigidbody>().velocity = tangent;



                  void Update()
                  //apply the vortex force
                  foreach(GameObject g in RigidBodies)
                  //force them toward the center
                  Vector3 direction = Vortex.transform.position - g.transform.position;
                  g.GetComponent<Rigidbody>().AddForce(direction.normalized * Time.deltaTime * VortexStrength);








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 at 17:31









                  Leo Bartkus

                  831411




                  831411



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262748%2funity3d-how-to-apply-a-vortex-like-force-to-objects%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      Node.js Script on GitHub Pages or Amazon S3

                      Museum of Modern and Contemporary Art of Trento and Rovereto