Reputation: 179
I am making a game that uses physics. I have a ball, and when it reaches a certain area, say
ball.x > 100 and ball.x < 110 and ball.y > 100 and ball.y < 110
I want the linear velocity of that ball to slow down, but not stop. I tried using ball:setLinearVelocity( 0, 0)
That works okay, but I still want the ball to have some, say half, momentum. Any thoughts?
Upvotes: 2
Views: 664
Reputation: 1
If your object doesn't have any damping the object may just keep cruising at the same speed through your zone. You may need to fire some reverse velocity to kill some of the speed. Or add some damping so that if you have zero lin vel then it will will want to slow quicker.
Upvotes: 0
Reputation: 8000
Call me crazy, but if your goal is to halve the velocity, couldn't you use getLinearVelocity
, divide by two, and set that as the velocity?
local vx, vy = ball:getLinearVelocity()
ball:setLinearVelocity(vx / 2, vy / 2)
Upvotes: 3