"Balloon" or object that has a "reverse gravity" force

Hey guys I have searched the forums for answers on this but can't come up with much.

I'm looking to create a scenario where there is global gravity and objects are affected by it. I.e. a box is dynamic physics body. The trick is that I want to have a balloon that is "floating" in the opposite direction of the gravity but also has enough "upward" force to lift the box if they were attached.

I've tried to use applyforce but the "balloon" seems to only move "upward" temporarily. I need it to have a constant "negative gravity"

Any help would be greatly appreciated, as I'm a LUA/OOP noob.

THANKS!!

Use applyForce repeatedly in an enterFrame event listener.

Duh! Yep. I'm a noob.

Thanks jhocking! Makes sense.

Hi,

I have a similar problem. I need to create a body without gravity effect. In an enterFrame event listener I use applyForce, but a body just flies up. Here is my main.lua file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local physics = require("physics");
physics.start();
gx, gy = physics.getGravity();
 
function update(e)
        for i=1,bullets.numChildren do
                local bullet = bullets[i];
                bullet:applyForce( 0, -gy, bullet.x, bullet.y ); 
        end;
end;
 
function addBullet()
        local bullet = display.newImage( "bullet.png", 160, 240, true );
        physics.addBody( bullet, { density=0.6, friction=0.6, bounce=0.4, radius=4 } );
        bullet.isBullet=true;
        bullets:insert(bullet);
end;
        
function create()
        g = display.newGroup();
        bullets = display.newGroup();
        g:insert(bullets);
end;
 
create();
addBullet();
Runtime:addEventListener( "enterFrame", update );
views:1515 update:2011/10/4 8:06:35
corona forums © 2003-2011