object:getLinearVelocity stop when velocity is low?

Hello, i got this code to tell the object not to spin around but just tilt alittle.

The problem is that when it slows down it keeps jumping slowly like forever.

Is there any good way to determin if it moves slowly both vx and vy
and then stop the motion?

local vx, vy = object:getLinearVelocity()

local angle = math.atan2(vy, vx) * 360/math.pi

if(angle >= 75) then
angle = 75
elseif(angle <=-75) then
angle = -75
end

object.rotation = angle

I used:

1
2
vx, vy = player:getLinearVelocity()
player:setLinearVelocity(vx*.9,vy*.9)

Yeah problem is that i want the object to move like normal but when it has almost stopped moving it starts jumping upp like 5px and 5px to the left and i want it to stop totally :)

Is there any good way to determin if it moves slowly both vx and vy
and then stop the motion?

Yes :)

1
2
3
4
5
6
local function stopMoving ()
vx, vy = object:getLinearVelocity()
  if vx < 100 and vy < 100 then
    -- Cancel movement here using object:setLinearVelocity(0,0) or the like
  end
end

I used that, but my object gets somekind of attack and starts jumping and the values get wierd when its nearly stops, and the vx and vy values jumps from 20 to 80 back and forth...

views:1566 update:2011/10/15 14:27:43
corona forums © 2003-2011