I’m trying to convert the UserAcceleration.x into a constant velocity. How can I go about doing this? I assume it has to do something with calculus. Thanks in advance.

@Leviathan I’m not quite sure what you are getting at, but…

If you have a formula for the acceleration at a time t, then yes, you could use calculus to find the formula for the velocity at the time t.

But I bet you want to have the acceleration controlled by the user, who can change both the amount and direction of the acceleration. The acceleration will change the velocity, of course. Suppose the acceleration was 1 inch per second squared, which is “1 inch per second” per second. This means that the velocity will change by 1 inch per second every second. If the velocity started at 2.5 inches per second, after 3 seconds the velocity would be 5.5 inches per second.

But within that 3 second period, the velocity is always changing. So what you do is break down the time into, say, every 1/60th of a second as Codea calls the draw function, and at each moment apply the current acceleration to the current velocity: newV = oldV + A * (1/60) … something like that.

(The 1/60 is just the change in time, of course, and you might be simulating this using different units entirely. Instead of inches and seconds, it might be pixels and refresh number.)

And remember acceleration can be either positive or negative (slowing down) but the formula still works, and if it gives a negative V, well, then it’s just going in the other direction.

You do a similar thing to change the position as time passes with the current velocity: newP = oldP + V * (1/60).

You asked about the x direction, but this idea extends quite easily to two or three dimensions.

Does this help?

@Ceres hey so I ran into another problem, that does work. But I can’t seem to make velocity equal to zero when Accerlation is not being changed. The Accerlation is changing all the time, even when the ipad is still. Here I tell what I’m trying to do, the ipad is suppose to be flat on a table, and the x,y coordinates of a rectangle will be the same where ever the ipad is on the table. So if you move the ipad down (down on the y axis), the rectangle goes up. Making it seem like it stays In the same position. But really it’s just going up. I’ve been struggling to do this, but I can’t seem to do it. Your way of adding the velocity to Accerlation and dividing by time does work. But before I tested I knew that it would keep going in that direction you “threw” it in. I still tried out your work, and tried to change it, only to fail again. And I guess there is no integrator function for Lua, just looked it up. Can you or someone help me with this please?

Did you need something like this?

http://codea.io/talk/discussion/4962/gui-sort-of-thing-help/p1

Edit: sorry it was you who asked that question

@Coder yeah, haha. That one just helped me figure out the rotation of the ipad. Not the acceleration of it?

I had a go with this when we first got access to the user acceleration and came to the conclusion that it wasn’t accurate enough. You’d need to include the rotation rate to keep track of the orientation of the iPad, otherwise “up” and “along” keep changing their meanings. The acceleration is more to detect shaking than actual movement.