- Home /
Question by
Pi_3.14 · Feb 11, 2014 at 04:55 AM ·
accelerometermotion-tracking
Getting object to mimick motion of iPhone
Say I have a mesh in the shape of an iPhone. When I left my actual iPhone I want it to lift. When I lower the iPhone, I want it to lower.
I'm currently trying out:
void FixedUpdate( )
{
float y_acc = Input.acceleration.z + 1f; // z is the iOS vertical axis, and 'at rest' has acc.z=-1 i.e. 1G gravity downwards
rigidbody.AddForce( 0f, 100f * y_acc, 0f );
if( transform.position.y <= y_min ) {
rigidbody.MovePosition( new Vector3( transform.position.x, y_min, transform.position.z ) );
if( rigidbody.velocity.y < 0f )
rigidbody.velocity = Vector3.zero;
}
if( transform.position.y >= y_max ) {
rigidbody.MovePosition( new Vector3( transform.position.x, y_max, transform.position.z ) );
if( rigidbody.velocity.y > 0f )
rigidbody.velocity = Vector3.zero;
}
}
This solution just doesn't work properly. While it does something, it isn't right.
I'm aware there is a random-walk problem with accelerometer data, that is why I'm having to sandwich the y values.
I am aware that capturing orientation is relatively easy. The gyroscope gives absolute direction reading.
Comment
Your answer
Follow this Question
Related Questions
Virtual Reality: Move player when mobile moves 0 Answers
How to use an IMU with Unity? 1 Answer
Get Iphone gforce values. 2 Answers
Unity Realistic accelerometer controls 1 Answer
Input.acceleration on sphere with rigidbody(gravity) 1 Answer