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 [import]uid: 9577 topic_id: 15285 reply_id: 315285[/import]

I used:
[lua]vx, vy = player:getLinearVelocity()
player:setLinearVelocity(vx*.9,vy*.9)[/lua]

to decrease velocity prettily xD

(it sets the velocity to 0.9 of its current. [import]uid: 79135 topic_id: 15285 reply_id: 56454[/import]

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 :slight_smile: [import]uid: 9577 topic_id: 15285 reply_id: 56462[/import]

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

Yes :slight_smile:

[lua]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[/lua] [import]uid: 52491 topic_id: 15285 reply_id: 56489[/import]

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… [import]uid: 9577 topic_id: 15285 reply_id: 56492[/import]

Do you have a function that could be causing that? Is it colliding with anything? etc. [import]uid: 52491 topic_id: 15285 reply_id: 56631[/import]