YASQ : Yet Another Stupid Question

Hi,

Playing around with Corona and i’m asking myself: how to create an object (like a balloon) which can defie gravity and go ‘up’.

Have tried several thinks but the balloon always falls. Maybe i’m missing something.

Glad if someone can help me :slight_smile:

Thanks ! [import]uid: 96145 topic_id: 16179 reply_id: 316179[/import]

You need to constantly apply small upward linear impulses to the balloon:

[lua]local function defyGravity()
balloon:applyLinearImpulse( 0, -10, balloon.x, balloon.y )
end

Runtime:addEventListener( “enterFrame”, defyGravity)[/lua]

I haven’t tested this code but you sholud get the idea :slight_smile:
You might need to tweak the amount of the impulse depending on the density of the balloon

hope this helps

Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 16179 reply_id: 60199[/import]

Excellent ! Thanks Raul just what I was looking for ! [import]uid: 96145 topic_id: 16179 reply_id: 60207[/import]

A better way would be to set linear velocity
[lua]local function defyGravity()
balloon:setLinearVelocity(0,-10)
end[/lua]
or even a transition would do
[lua]local function defyGravity()
transition.to(balloon,{time=2000,y = balloon.y-200})
end[/lua]
[import]uid: 64174 topic_id: 16179 reply_id: 60217[/import]

are you using physics ?
in that case you can just use a -ve value for gravity.
[lua]physics:setGravity(0,-5) [/lua] ofcourse only if there are no other object which should fall down. :slight_smile: [import]uid: 71210 topic_id: 16179 reply_id: 60281[/import]