Flicking object

Hi,
I am currently working on a game were a user needs to flick a object across the screen. I am currently using the Gameui.lua to move the object across the screen but was wondering if there was a better way to do this.

Also please take note I am doing this in a 0 gravity environment because you look down on the game, simular to the pool sample code. The only difference is I want the object to not fly all over the screen but to move a short distance an stop. Any suggestions on this would be welcome. [import]uid: 104852 topic_id: 20084 reply_id: 320084[/import]

You could try adjusting the physics properties of the object, like setting linear damping, friction, density, etc.

myObject.linearDamping = 10
playerMaterial = { density = 2.0, friction = 10.0, bounce = 0.0}

Give it a try!

-Mario [import]uid: 11636 topic_id: 20084 reply_id: 78428[/import]

I tried setting the lineardamping property but it appears to have no affect. Any idea why? [import]uid: 104852 topic_id: 20084 reply_id: 78430[/import]

Are you moving the object with force or linearVelocity?

Take a look at the MultiPuck example, that may be closer to what you want.

CoronaSDK > SampleCode > Physics > MultiPuck.

Peach :slight_smile: [import]uid: 52491 topic_id: 20084 reply_id: 78458[/import]

I am using the gameUI.dragBody code from MultiPuck, the problem is now that the user can keep dragging the object. For instance into the goal, instead of flicking it in… [import]uid: 104852 topic_id: 20084 reply_id: 78600[/import]

Perhaps prevent the user from dragging below a certain Y coordinate on the screen, then? (Assuming the goal is at the top of the screen.)

Peach :slight_smile: [import]uid: 52491 topic_id: 20084 reply_id: 78641[/import]

That’s the problem there are two goals and they move positions. [import]uid: 104852 topic_id: 20084 reply_id: 78701[/import]

OK problem solved, here is what I did:

To solve the first problem I was having with moving the object, I simply change the way the user moves it to a way simular to the simple pool sample code.

I fixed the second problem with the object not slowing down by writhing the following code:

[lua]function listener2( event )
vx, vy = pen:getLinearVelocity()
if (vx < -4 ) then
vx = (vx + 5)
end
if (vx > 4 ) then
vx = (vx - 5)
end
if (vy < -4 ) then
vy = (vy + 5)
end
if (vy > 4 ) then
vy = (vy - 5)
end
if (vx < -30 ) then
vx = (vx + 25)
end
if (vx > 30 ) then
vx = (vx - 25)
end
if (vy < -30 ) then
vy = (vy + 25)
end
if (vy > 30 ) then
vy = (vy - 25)
end
if (vx < 5) then
if (vx > -5) then
pen.angularVelocity = 0
pl = 1
end
end
if (vy < 5) then
if (vy > -5) then
pen.angularVelocity = 0
end
end
pen:setLinearVelocity( vx, vy )

–May cause object to jerk some, adjust for each object
end
timer.performWithDelay( 300, listener2, 0 )[/lua] [import]uid: 104852 topic_id: 20084 reply_id: 78732[/import]

You could check coords and compare with the goals locations using a Runtime listener.

Peach :slight_smile: [import]uid: 52491 topic_id: 20084 reply_id: 78753[/import]