×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Question how to smoothly move object on accelerometer value change

    Hi All,

    I am writing a game were I am moving objects on accelerometer change. I want object to move very smoothly, even small change in accelerometer should update position of object.

    how to deal with accelerometer noise here? That is accelerometer event will keep on firing, even I am not moving my device.

    I have browsed for it but could not found any good solution.

    I have also tried solutions like setting threshold, or keep a last updated value in a variable and it if changes then update object position etc. But these will not help in smooth movement.

    Games on iphone and android market does this. Object moves very smoothly.

    Suggestions please.

    Thanks

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    919

    Re: how to smoothly move object on accelerometer value change

    Its all about translating sensor data to physics. I'm no expert on DirectX (done some XNA some time ago) but as I recall it, sensor data by it self will not allow you to have a smooth animation.

    I recalled looking at an example of sensor usage and movement on a DirectX project. Its on this link . Can you give a look and see if it addresses your problem?

    Again as I said I'm no expert, and without looking at code its a bit difficult to help.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: how to smoothly move object on accelerometer value change

    Quote Originally Posted by joaocardoso View Post
    Its all about translating sensor data to physics. I'm no expert on DirectX (done some XNA some time ago) but as I recall it, sensor data by it self will not allow you to have a smooth animation.

    I recalled looking at an example of sensor usage and movement on a DirectX project. Its on this link . Can you give a look and see if it addresses your problem?

    Again as I said I'm no expert, and without looking at code its a bit difficult to help.
    Thanks for reply, even this game is written in xna. Its a 2d game and I have wrote below code -
    I have assigned accelerometer in start of game.
    _accelerometer = new Accelerometer();
    if (_accelerometer.State == SensorState.Ready)
    {
    _accelerometer.CurrentValueChanged += (s, e) =>
    {
    acceloVelocity.X = e.SensorReading.Acceleration.X;
    acceloVelocity.Y = e.SensorReading.Acceleration.Y;
    };
    _accelerometer.Start();
    }
    and in update I am use below code
    float movement = 0.0f;
    if (System.Math.Abs(acceloVelocity.X) > accelThreshold)
    {
    movement = acceloVelocity.X * acceleoSpeed;
    }
    here accelThreshold is a threshold variable and I tried different combination value for it.

    Please let me know if anything wrong there in my code.

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2009
    Posts
    200

    Re: how to smoothly move object on accelerometer value change

    I would try (and have in the past) implement moving average filtering to accelerometer data. Accelerometer is always going to be noisy and moving average is very simple way to "smoothen" it.

    So just keep, let's say, 5 latest acceleromoter values in memory and use average of those 5 latest values as your input.

  5. #5
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: how to smoothly move object on accelerometer value change

    You should use filtering as mikkovtr said. Check out this blog post by Jeff Prosise: Using the Accelerometer in Silverlight for Windows Phone and this one by Dave Edson Using the Accelerometer on Windows Phone 7.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: how to smoothly move object on accelerometer value change

    Quote Originally Posted by to_pe View Post
    You should use filtering as mikkovtr said. Check out this blog post by Jeff Prosise: Using the Accelerometer in Silverlight for Windows Phone and this one by Dave Edson Using the Accelerometer on Windows Phone 7.
    Thanks for reply. Article looks great and will surely help me to improve my code. But just a thought, if we keep on working with last stored value, what if i will not move my mobile. Do still I should calculate as per last 5 values?

  7. #7
    Nokia Developer Champion
    Join Date
    Nov 2009
    Posts
    200

    Re: how to smoothly move object on accelerometer value change

    Quote Originally Posted by sunder.tinwar View Post
    Thanks for reply. Article looks great and will surely help me to improve my code. But just a thought, if we keep on working with last stored value, what if i will not move my mobile. Do still I should calculate as per last 5 values?
    If you are receiving new values at constant rate, just keep averaging them. If there is a pause in new values from accelerometer, then you have to think what's the best way, it depends on what you are actually doing.

  8. #8
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: how to smoothly move object on accelerometer value change

    Quote Originally Posted by sunder.tinwar View Post
    Thanks for reply. Article looks great and will surely help me to improve my code. But just a thought, if we keep on working with last stored value, what if i will not move my mobile. Do still I should calculate as per last 5 values?
    As far as I know, you will still get data even if you don't move your device. The sensor reports back in intervals, so you can safely use last 5 values.

  9. #9
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: how to smoothly move object on accelerometer value change

    Quote Originally Posted by to_pe View Post
    As far as I know, you will still get data even if you don't move your device. The sensor reports back in intervals, so you can safely use last 5 values.
    Yes, you are right, even if we don't move device, sensor will report back interval. Even if we use last 5 or n accelerometer value average, we still got to use threshold. Else object will keep on moving even we don't move mobile.

  10. #10
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: how to smoothly move object on accelerometer value change

    Guys anyone tried any solution.

Similar Threads

  1. Replies: 2
    Last Post: 2010-07-28, 02:50
  2. How to Move Controls (change location) ?
    By goktoure in forum Symbian
    Replies: 1
    Last Post: 2010-07-17, 18:38
  3. how to move a m3g object
    By ronykucse in forum Mobile Java Games
    Replies: 1
    Last Post: 2010-02-05, 09:51
  4. How to change the charset for Font object.
    By pop2518 in forum Mobile Java General
    Replies: 1
    Last Post: 2004-02-09, 12:16

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •