Search Unity

RotateAround question...

Discussion in 'Scripting' started by dcarlson314, Oct 26, 2010.

  1. dcarlson314

    dcarlson314

    Joined:
    Apr 1, 2009
    Posts:
    45
    Hey everyone...

    How can I make RotateAround behave so it's NOT cumulative, but relative? eg: I tilt a device, and a gameobject rotates around another object RELATIVE to the device. So, when I stop tilting, the object stops rotating.

    Thanks!
     
  2. dcarlson314

    dcarlson314

    Joined:
    Apr 1, 2009
    Posts:
    45
  3. Ostagar

    Ostagar

    Joined:
    Sep 29, 2010
    Posts:
    445
    A device that you tilt to control the rotation of another device--that sounds like a control lever. If you can trigger an event whenever the lever is tilted, or at least check very frequently, you could write an onTilt() or checkTilt() procedure that compares the current absolute tilt of the lever to the last recorded absolute tilt of the lever and then makes a corresponding change to the rotation of the other object via RotateAround().
     
  4. dcarlson314

    dcarlson314

    Joined:
    Apr 1, 2009
    Posts:
    45
    Hey Ostagar...

    Thanks for the response, but when I mentioned "device" I meant like an iPhone, iPad, iPod, Android, etc. :)

    Currently, the only way I can think of doing this is to get an accurate tilt delta (like using mouse delta for first person shooters) and have that multiply into a rotation amount in RotateAround(). The only accurate way to get the tilt delta that I know of is by using Input.accelerationEvents, but that doesn't seem to work at all with Unity Remote. Kinda makes it hard to test! ;-)

    I've made my own tilt delta running in Update() but it wasn't accurate enough. The rotated object would get out of sync with the device. If I started with the device flat and the object neutral, it would be off within several seconds of tilting and shaking the device.

    So I was just wondering if there was another "outside-the-box-but-efficient" method of doing this same thing that kept things locked in place (relative) to the tilt of the device.

    Thanks again!