# Blowing Bubbles (Resolved)

**URL:** <https://forums.solar2d.com/t/blowing-bubbles-resolved/312596>\
**Category:** Physics\
**Created:** [April 16, 2013, 8:57pm UTC](https://forums.solar2d.com/t/blowing-bubbles-resolved/312596 "2013-04-16T20:57:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Egret](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/e/7ea924/32.png) [@Egret](https://forums.solar2d.com/u/Egret)\
**Post date:** [April 16, 2013, 8:57pm UTC](https://forums.solar2d.com/t/blowing-bubbles-resolved/312596/1 "2013-04-16T20:57:16Z")

</div>

**This is my first attempt at using physics bodies and I’m trying to create an animation effect where a character is blowing bubbles. &nbsp;I’m having problems achieving a floating effect, the smaller bubbles move much too fast while the larger bubbles stagnate. &nbsp;I’m also not happy with how much the bubbles bounce off each other and might prefer they stick to each other. &nbsp;**

**Thanks!**

```
local physics = require("physics")physics.start() physics.setGravity(0, .1) display.setDefault( "background", 255, 255, 255 ) local function newBubble() &nbsp;&nbsp;&nbsp;&nbsp;r = (math.random(15, 35)) &nbsp;&nbsp;&nbsp;&nbsp;forceX = -3 &nbsp;&nbsp;&nbsp;&nbsp;forceY = -1&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;bubble = display.newCircle(200, 200, r) &nbsp;&nbsp;&nbsp;&nbsp;bubble:setFillColor(135,206,250) &nbsp;&nbsp;&nbsp;&nbsp;bubble:setStrokeColor(0,0,255) &nbsp;&nbsp;&nbsp;&nbsp;bubble.strokeWidth = 2 &nbsp;&nbsp;&nbsp;&nbsp;bubble.x = 500 &nbsp;&nbsp;&nbsp;&nbsp;bubble.y = 500 &nbsp;&nbsp;&nbsp;&nbsp;bubble.alpha = .5 &nbsp;&nbsp;&nbsp;&nbsp;physics.addBody(bubble, "dynamic", {bounce=0, friction=1, density=0, radius=r}) &nbsp;&nbsp;&nbsp;&nbsp;bubble:applyForce(forceX, forceY) end newBubble() timer.performWithDelay(800, newBubble, 10) &nbsp;
```

---

<div class="post-metadata">

**Author:** ![Egret](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/e/7ea924/32.png) [@Egret](https://forums.solar2d.com/u/Egret)\
**Post date:** [April 17, 2013, 3:36am UTC](https://forums.solar2d.com/t/blowing-bubbles-resolved/312596/2 "2013-04-17T03:36:55Z")

</div>

**After I increased the size of the bubbles everything else started cooperating like I thought it should. &nbsp;For some reason the small bubbles launched much faster than the bigger ones. &nbsp;**

**Solution…**

```
local physics = require("physics")physics.start() physics.setGravity(0, .1) display.setDefault( "background", 255, 255, 255 ) local bg = display.newImage ("BriannaBear.jpg") bg.x = 700 bg.y = 500 local function newBubble() &nbsp;&nbsp;&nbsp;&nbsp;r = (math.random(23, 36)) &nbsp;&nbsp;&nbsp;&nbsp;forceX = -r/10 &nbsp;&nbsp;&nbsp;&nbsp;print (forceX) &nbsp;&nbsp;&nbsp;&nbsp;forceY = -(math.random()) &nbsp;&nbsp;&nbsp;&nbsp;bubble = display.newCircle(200, 200, r) &nbsp;&nbsp;&nbsp;&nbsp;bubble:setFillColor(135,206,250) &nbsp;&nbsp;&nbsp;&nbsp;bubble:setStrokeColor(0,0,255) &nbsp;&nbsp;&nbsp;&nbsp;bubble.strokeWidth = 2 &nbsp;&nbsp;&nbsp;&nbsp;bubble.x = 365 &nbsp;&nbsp;&nbsp;&nbsp;bubble.y = 300 &nbsp;&nbsp;&nbsp;&nbsp;bubble.alpha = .5 &nbsp;&nbsp;&nbsp;&nbsp;physics.addBody(bubble, "dynamic", {bounce=.05, friction=0, density=0, radius=r}) &nbsp;&nbsp;&nbsp;&nbsp;bubble:applyForce(forceX, forceY) end newBubble() timer.performWithDelay(1000, newBubble, 50) &nbsp;
```

---

<div class="post-metadata">

**Author:** ![Egret](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/e/7ea924/32.png) [@Egret](https://forums.solar2d.com/u/Egret)\
**Post date:** [April 17, 2013, 3:36am UTC](https://forums.solar2d.com/t/blowing-bubbles-resolved/312596/3 "2013-04-17T03:36:55Z")

</div>

**After I increased the size of the bubbles everything else started cooperating like I thought it should. &nbsp;For some reason the small bubbles launched much faster than the bigger ones. &nbsp;**

**Solution…**

```
local physics = require("physics")physics.start() physics.setGravity(0, .1) display.setDefault( "background", 255, 255, 255 ) local bg = display.newImage ("BriannaBear.jpg") bg.x = 700 bg.y = 500 local function newBubble() &nbsp;&nbsp;&nbsp;&nbsp;r = (math.random(23, 36)) &nbsp;&nbsp;&nbsp;&nbsp;forceX = -r/10 &nbsp;&nbsp;&nbsp;&nbsp;print (forceX) &nbsp;&nbsp;&nbsp;&nbsp;forceY = -(math.random()) &nbsp;&nbsp;&nbsp;&nbsp;bubble = display.newCircle(200, 200, r) &nbsp;&nbsp;&nbsp;&nbsp;bubble:setFillColor(135,206,250) &nbsp;&nbsp;&nbsp;&nbsp;bubble:setStrokeColor(0,0,255) &nbsp;&nbsp;&nbsp;&nbsp;bubble.strokeWidth = 2 &nbsp;&nbsp;&nbsp;&nbsp;bubble.x = 365 &nbsp;&nbsp;&nbsp;&nbsp;bubble.y = 300 &nbsp;&nbsp;&nbsp;&nbsp;bubble.alpha = .5 &nbsp;&nbsp;&nbsp;&nbsp;physics.addBody(bubble, "dynamic", {bounce=.05, friction=0, density=0, radius=r}) &nbsp;&nbsp;&nbsp;&nbsp;bubble:applyForce(forceX, forceY) end newBubble() timer.performWithDelay(1000, newBubble, 50) &nbsp;
```
