Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Dice

Discussion in 'iOS and tvOS' started by bergerbytes, Apr 15, 2010.

  1. bergerbytes

    bergerbytes

    Guest

    Can someone point me in the right direction for getting dice to behave properly when the device is shaken?

    Thanks,
    -Mike
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,625
    Hi, can you clarify what you are trying to do?

    Are you just wanting the shake to trigger some animation/action or are you wanting to physically simulate real dice?

    For the simulation you could create an object with some children that each have a box collider , corresponding to the edges of the iphone (all six, although you probably want the screen collider to be a bit higher than the phone). Make your camera a child of this object too.
    Code (csharp):
    1.  
    2. -Box (GameObject with script)
    3.  - ColliderRight
    4.  - ColliderLeft
    5.  - ColliderTop
    6.  - ColliderBotoom
    7.  - ColliderBase
    8.  - ColliderScreen
    9.  - Camera
    10. -Dice 1
    11. -Dice 2
    Then translate (rotate) this object based on the accelerometer input. The accelerometer tells you which way gravity is pulling so should be fairly trivial to turn this into an orientation for your Box game object.

    As long as your dice are small (and rigidbodies with colliders) they should start falling and bouncing around quite realistically.
     
  3. bergerbytes

    bergerbytes

    Guest

    Sorry for the unclear goal. You're approach is interesting, originally I was trying to move the dice vs. the "world" it's in. I will try this tomorrow..err...today, but later.

    Thanks,
    -Mike
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,625
    That should be fine too, I figured it might be easier to translate the accelerometer data to "box" rotations.
     
  5. bergerbytes

    bergerbytes

    Guest

    I agree, I was having trouble getting them to look real and change the side they were facing, which made them quite useless. I'll post my results in the next day or two.

    -Mike
     
  6. bergerbytes

    bergerbytes

    Guest

    I'm guessing this won't work

    Code (csharp):
    1. this.gameObject.transform.Rotate(iPhoneInput.acceleration);
     
  7. bergerbytes

    bergerbytes

    Guest

    I'm not getting this to work, I feel like it could be something small i'm missing.
     
  8. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the code you have got so far and say what is going wrong with it?
     
  9. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    Check ur private msg in UnityForum Inbox and reply...