I am trying to rotate an object (in this case a box) so that it is always facing towards the top of the device. I created a simple function that calculates this angle based on xGravity and yGravity and am assigning the result to box.rotation. The problem is, the box slowly rotates to the correct position and lags behind the hardware. Even after I have stopped tilting the device the box will continue rotating until it catches up. The only exception is when xGravity changes from positive to negative or vice-versa. Then the box instantly jumps to the proper place, which, while unplanned, is actually the output I am looking for all of the time… not just when xGravity changes its sign. I assume that this has something to do with how the accelerometer is processed. Does anyone have any ideas how I can ge the results I expect? Is there some way to get the accelerometer to notice quick movements without requiring xGravity to change to positive or negative? Thanks in advance. [import]uid: 16410 topic_id: 5467 reply_id: 305467[/import]
Reviving this question; as I too am having this same issue. My object too slowly rotates toward the correct position and lags behind the hardware.
I’ve tried a number of different techniques, such as playing with the system.setAccelerometerInterval() at all different frame rates and hz; and haven’t had any luck.
I’ve tried putting the rotation code within the event listener instead of the update loop - nothing’s helped.
Could it be the way I’m calculating the rotation’s angle? I’m using atan2(event.xGravity, event.yGravity)
Is there something I need to do with xInstant/yInstant to prevent the rotation from rotating TOWARD the correct position; and instead instantly appearing at the accelereometer’s angle? I’m not really sure what xInstant/yInstant does and how you can incorporate them into the calculation of the angle…
Anyone got any ideas? [import]uid: 144339 topic_id: 5467 reply_id: 119840[/import]
If you use a simple folow rotation, perhaps you need to add the variable responsible for the rotaion speed? object.rotation = object.rotation + some variable depends on the length of the hypotenuse. Or use the spin momentum with object.angularVelocity = some variable etc. based on the length of the hypotenuse [import]uid: 26141 topic_id: 5467 reply_id: 119872[/import]
Hi justfunk,
Thanks for the reply - it’s a good idea; but in this case, mtnbkrpro and I weren’t using a “follow rotation” method with a rotation speed - we were instantly setting the rotation of the object to the angle of the accelerometer - eg obj.rotation = math.atan2(event.xGravity, event.yGravity)
The problem is that the angle calculated seems to lag behind the hardware’s rotation - like the accelerometer events are a second or two behind the actual device’s readings…
As I said earlier, I’ve tried many different combinations of frame rates and system.setAccelerometerInterval values; but none have been able to get the readings and the device’s actual value to synch up.
Has anyone else encountered something like this…? Why does this happen? [import]uid: 144339 topic_id: 5467 reply_id: 119993[/import]
Reviving this question; as I too am having this same issue. My object too slowly rotates toward the correct position and lags behind the hardware.
I’ve tried a number of different techniques, such as playing with the system.setAccelerometerInterval() at all different frame rates and hz; and haven’t had any luck.
I’ve tried putting the rotation code within the event listener instead of the update loop - nothing’s helped.
Could it be the way I’m calculating the rotation’s angle? I’m using atan2(event.xGravity, event.yGravity)
Is there something I need to do with xInstant/yInstant to prevent the rotation from rotating TOWARD the correct position; and instead instantly appearing at the accelereometer’s angle? I’m not really sure what xInstant/yInstant does and how you can incorporate them into the calculation of the angle…
Anyone got any ideas? [import]uid: 144339 topic_id: 5467 reply_id: 119840[/import]
If you use a simple folow rotation, perhaps you need to add the variable responsible for the rotaion speed? object.rotation = object.rotation + some variable depends on the length of the hypotenuse. Or use the spin momentum with object.angularVelocity = some variable etc. based on the length of the hypotenuse [import]uid: 26141 topic_id: 5467 reply_id: 119872[/import]
Hi justfunk,
Thanks for the reply - it’s a good idea; but in this case, mtnbkrpro and I weren’t using a “follow rotation” method with a rotation speed - we were instantly setting the rotation of the object to the angle of the accelerometer - eg obj.rotation = math.atan2(event.xGravity, event.yGravity)
The problem is that the angle calculated seems to lag behind the hardware’s rotation - like the accelerometer events are a second or two behind the actual device’s readings…
As I said earlier, I’ve tried many different combinations of frame rates and system.setAccelerometerInterval values; but none have been able to get the readings and the device’s actual value to synch up.
Has anyone else encountered something like this…? Why does this happen? [import]uid: 144339 topic_id: 5467 reply_id: 119993[/import]