Search Unity

Planetary Gravity w/ Sound launching

Discussion in 'Scripting' started by 3xternal, Mar 3, 2010.

  1. 3xternal

    3xternal

    Joined:
    Mar 3, 2010
    Posts:
    3
    I am trying to make a simple scene using a sphere (as a planetary mass) and some surrounding cubes that "lift off" the surface of the sphere when audio levels rise via microphone input. I need to suspend the gravity of the sphere, so it floats, I need to create gravity within the sphere and the sphere alone, and i need the cubes to react to that gravity. In cases of dead silence, the cubes should cling to the sphere's surface. At moments of high audio, they should "leap" off the sphere's surface, only to return when audio dips.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Hi, welcome to the forum!

    I'm guessing you already have the code to sample the microphone and detect the changes in volume? I don't think there is any way to do this in Unity, except with C/C++ code added via a plugin.

    If you already have that in place, there are a few ways you could handle the cubes and the planet. If you want to use physics, you should switch off gravity for all the objects. As for attracting the cubes, probably the easiest way to go is to use spring joints connected from the cubes to the centre of the planet. Then, apply a force outward from the centre of the planet to all the cubes in proportion to the volume of the sound. You can use rigidbody.AddExplosionForce to push the cubes away without the bother of calculating vectors for the forces.