- Home /
Dice shaking (mobile)
Hello everyone!
"i just want to add a force to an object in a physic 3d world according to accelerometer value changes. This is the main problem."
background:
I would like to create a dice shaking game. The user shakes the mobile device and the 3d dices on the screen roll around. That's all. I have no idea for now about how to realize this, surely i'll have to use physics and forces and make them related to accelerometer values. Anyone can suggest me some code to start from or something i can read? It seems there's no much documentation about this particular case on the web. I've only found this question http://answers.unity3d.com/questions/53751/shake-object-on-iphone.html?sort=oldest but the solution doesn't explain much.
You need to break this down, then resolve all the smaller problems.
1/ create a dice.
2/ make the dice roll on command.
3/ work out how to deter$$anonymous$$e when the dice has stopped rolling, and deter$$anonymous$$e the face that is facing up.
4/ use the accelerometer to trigger the dice-roll.
some reading to get you started : https://www.google.com/search?btnG=1&pws=0&q=unity+dice+roll
i just want to add a force to an object in a physic 3d world according to accelerometer value changes. This is the main problem.
Not sure why that should be a problem, Input.acceleration gives a Vector3 value, and Rigidbody.AddForce takes a Vector3 value. All you have to do is make sure the axes are lined up and have the right size value.
some links: http://docs.unity3d.com/Documentation/ScriptReference/Input-acceleration.html
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html
Have a look at the Unity Examples for learning to use and implement the accelerometer : http://unity3d.com/support/resources/example-projects/iphone-examples
Download and look at Roll-A-Ball =]
also http://answers.unity3d.com/questions/63433/moving-an-object-with-accelerometer-using-unity-ip.html
How did you go? Another link has just popped up in the answers : http://vimeo.com/48791493
I think your question is more about detecting the magnitude of the change in accelerometer value over time. So in the first moment, you read the outputs of accelerometer, then in the next moment you read again and compare the change in value. If that change is greater than a certain amount, you know how much the phone has moved within a certain timeframe. If that value is greater than some small number, then shake the dice by the amount of change in the accelerometer. I havn't played with accelerometers myself yet, but your question has made me curious and I shall do some experimenting of my own. Don't give up, and keep searching for videos that may help.
Answer by Anusha · Sep 04, 2012 at 12:24 PM
vector3 forward = new Vector3(Input.acceleration.x,Input.acceleration.y , Input.acceleration.z);
rigidbody.AddForce(forward,ForceMode.Acceleration);
Your answer
Follow this Question
Related Questions
Make object shaking when is damaged 1 Answer
Camera Shaking Problem 0 Answers
how can my gameobject stop shaking? 1 Answer
Shaking angles using gyro attitude 1 Answer