Move a physical ball with the touch

A distance of 0 causes division by-zero.

Make this change:

 local dx = event.x - event.xStart local dy = event.y - event.yStart local distance = math.sqrt( dx \* dx + dy \* dy ) if( distance \> 0.01 ) then -- This is how you normalize (not by using math.abs()): local vx = dx/distance local vy = dy/distance -- local magnitude = self.factor \* distance/dt --print( distance, dt, magnitude, self.t0, system.getTimer(), dx, dy ) magnitude = (magnitude \> self.limit) and self.limit or magnitude magnitude = magnitude \* self.mass -- self:applyLinearImpulse( vx \* magnitude, vy \* magnitude, self.x, self.y ) end -- self.lx = nil self.ly = nil

Thanks again!

Still here to ask for advice.

Currently if I run a long stretch(more than a few seconds) and after release, the ball will have a small push.

I know this happens because I have sampled a lot of time.

While playing tiger ball it seems that only the last stretch is considered.

So to do this I am storing in a table all the positions it makes in the last 1-2 seconds then I delete all the previous ones.

This all around works. But I’d love to hear what you think and how you can solve it.