recreating transition:to with linear Impulse or apply linear force.

Hi Im just trying to create a flick effect, I have experimented with transition:to and this kind of does the effect I want but not in a physics sense. I want the object when swiped in a direction to have force applied in that direction , if it hits a obstacle then acts appropriately e.g. bouncing off the obstacle.

Heres an example to work from, I want to be able to flick in the direction of the event:

Many thanks.

[code]
physics = require(“physics”)
physics.start()
physics.setScale(50)
physics.setGravity(0,0)
local player = display.newRect(0,0, 40, 40)
player.x = 200
player.y = 200
physics.addBody( player, { density = 1.0, friction = 0.3, bounce = 0.2 } )
Runtime:addEventListener(“touch”, function( event) --Add some touch listeners to the player–
–player.x = event.x –
–player.y = event.y – this moves object to location
– player:applyLinearImpulse( 1, 1, player.x, player.y ) – how do I get same as below with impulse
transition.to( player, { time=1500, x=event.x, y=event.y} )
end )

[/code] [import]uid: 118379 topic_id: 21816 reply_id: 321816[/import]

It sounds like the MultiPuck example might be what you’re after.

CoronaSDK > SampleCode > Physics > MultiPuck

Check that out :slight_smile:

Peach [import]uid: 52491 topic_id: 21816 reply_id: 86801[/import]

Thanks Peach, like most times I end up sussing it myself but I always ask the question just in case I cant suss it and end up falling out with my keyboard and mouse. :slight_smile:

Here’s the mantra:

[code]

function dragPlayer( event)

if “began” == event.phase then
display.getCurrentStage():setFocus(event.target)
end
if “moved” == event.phase then

if (line) then
line.parent:remove(line)
end
line = display.newLine(player.x, player.y, event.x, event.y)
line:setColor(200,200,0,100)
line.width = 8

end
if “ended” == event.phase then
player:applyForce((player.x - event.x)*-1, (player.y - event.y)* -1, player.x, player.y)
player.linearDamping = 1.9;
display.getCurrentStage():setFocus( nil )
movedPlayer = true
end

end
[/code] [import]uid: 118379 topic_id: 21816 reply_id: 86832[/import]

Good stuff; thanks for sharing :slight_smile:

And I hear you about the keyboard/mouse :wink: [import]uid: 52491 topic_id: 21816 reply_id: 86860[/import]