Egret
April 16, 2013, 8:57pm
1
This is my first attempt at using physics bodies and I’m trying to create an animation effect where a character is blowing bubbles. I’m having problems achieving a floating effect, the smaller bubbles move much too fast while the larger bubbles stagnate. I’m also not happy with how much the bubbles bounce off each other and might prefer they stick to each other.
Thanks!
local physics = require("physics")physics.start() physics.setGravity(0, .1) display.setDefault( "background", 255, 255, 255 ) local function newBubble() r = (math.random(15, 35)) forceX = -3 forceY = -1 bubble = display.newCircle(200, 200, r) bubble:setFillColor(135,206,250) bubble:setStrokeColor(0,0,255) bubble.strokeWidth = 2 bubble.x = 500 bubble.y = 500 bubble.alpha = .5 physics.addBody(bubble, "dynamic", {bounce=0, friction=1, density=0, radius=r}) bubble:applyForce(forceX, forceY) end newBubble() timer.performWithDelay(800, newBubble, 10)
Egret
April 17, 2013, 3:36am
2
After I increased the size of the bubbles everything else started cooperating like I thought it should. For some reason the small bubbles launched much faster than the bigger ones.
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() r = (math.random(23, 36)) forceX = -r/10 print (forceX) forceY = -(math.random()) bubble = display.newCircle(200, 200, r) bubble:setFillColor(135,206,250) bubble:setStrokeColor(0,0,255) bubble.strokeWidth = 2 bubble.x = 365 bubble.y = 300 bubble.alpha = .5 physics.addBody(bubble, "dynamic", {bounce=.05, friction=0, density=0, radius=r}) bubble:applyForce(forceX, forceY) end newBubble() timer.performWithDelay(1000, newBubble, 50)
Egret
April 17, 2013, 3:36am
3
After I increased the size of the bubbles everything else started cooperating like I thought it should. For some reason the small bubbles launched much faster than the bigger ones.
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() r = (math.random(23, 36)) forceX = -r/10 print (forceX) forceY = -(math.random()) bubble = display.newCircle(200, 200, r) bubble:setFillColor(135,206,250) bubble:setStrokeColor(0,0,255) bubble.strokeWidth = 2 bubble.x = 365 bubble.y = 300 bubble.alpha = .5 physics.addBody(bubble, "dynamic", {bounce=.05, friction=0, density=0, radius=r}) bubble:applyForce(forceX, forceY) end newBubble() timer.performWithDelay(1000, newBubble, 50)