Superb FREE Box2d Physics Effects Inc Water/Liquid/Buoyancy...BUT...

OK, so for a new game that I’m creating I needed some way of creating a buoyancy effect that makes physics object float realistically when dropped into water. Something like this:

http://youtu.be/imzZnae4OHg

Playing around with physics and forces has not been working for me as I want so I did some searching for similar effects on the net. This led me to a web site where someone has created a buoyancy controller for Box2d and it works astonishingly well, it can be used FREELY, the code is provided…but it’s in AS3.

It can be freely downloaded as part of a controller pack that contains other effects like ‘Gravity’ and ‘Spring’. This set of effects would be invaluable to the Corona SDK community, and if I could, I would port them over myself and upload them to the Code Share for everyone here to use.
Check out the demo of the effect quality and features here:

http://personal.boristhebrave.com/project/controller-grab-pack/demo
So I’m reaching out to the wider Corona SDK community, of whom we have seen have some amazing coding skills that a newbie like me can only aspire to be as good as.

Is there anyone out there willing to port this working AS3 code to lua and upload to the Code Share for the Corona SDK community to benefit from?

If so, and so that people aren’t porting the same effect as someone else, download the project file from the link below, and post in this thread with what you will be working on.

Let’s do this…

Project File Download (and guys web site): http://personal.boristhebrave.com/project/controller-grab-pack
PS: How about starting with buoyancy effect as I’ve been trying for days and my head’s about ready to explode Ü [import]uid: 74503 topic_id: 16060 reply_id: 316060[/import]

this is the core of the bouyance in my opinion, I have had just a cursory glance at it.

[as3]
//Buoyancy
var buoyancyForce:b2Vec2 = gravity.Negative();
buoyancyForce.Multiply(density*area)
body.ApplyForce(buoyancyForce,massc);

//Linear drag
var dragForce:b2Vec2 = body.GetLinearVelocityFromWorldPoint(areac);
dragForce.Subtract(velocity);
dragForce.Multiply(-linearDrag*area);
body.ApplyForce(dragForce,areac);

//Angular drag
//TODO: Something that makes more physical sense?

body.ApplyTorque(-body.GetInertia()/body.GetMass()*area*body.GetAngularVelocity()*angularDrag)
[/as3]

The bouyancy is achieved by applying a negative force based on the mass of the object.

Need to look at this in its entirety when I get some time, anybody else want to give it a go

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16060 reply_id: 59705[/import]

@JayantV

I was hoping a talented someone like you would get on board with this.

I’m a newbie to programming in general, although I’m getting to grips well with Corona/Lua. However, I had a good read through the code with a naive optimism that maybe I might make an attempt at porting it to share. It’s beyond my scope however…for now. I’m keen to learn and contribute all I can - just as you do with your blog/tutorials which I follow.

These effects would be a huge addition to any number of games that the community could dream up. Not only that, it’s dissecting code like this that helps people like myself learn how to program - the math and functions behind them - it’s an invaluable learning tool.

So thanks to JayantV for becoming the first to reply to this thread, and I sincerely hope that he finds some spare time (of which I am sure there is little) to have a go a porting this to Lua.

I’m sure that as more people read and post to this thread, others will step up and bring what they can to the table. Looking through the forums at past posts, we’ve seen how forthcoming with help and experience members of the Corona community can be.

Thanks all… [import]uid: 74503 topic_id: 16060 reply_id: 59722[/import]

I believe buoyancy is actually part of the newer, 2.1 alpha version of box2dflash.

The problem with your request, is that for the most part, Box2D is implemented by Corona behind the scenes, and there are quite a few methods/parameters that are not accessible by Lua.

The other issue is that Box2dflash is itself a port of the C++ Box2D library.

That said, there is almost certainly a solution to adding a buoyancy effect in your Corona projects, but it’s probably not going to match the same quality and performance as the rest of the Box2D implementation.

Either way, looking forward to what either Ansca or the community can come up with. The roadmap does list “Fluid Dynamics” as one of the non-priority features to be added in the future… although I’m not sure if that also covers adding buoyancy to Box2D.

edit: also wanted to chime in that I think oz is correct with “The bouyancy is achieved by applying a negative force based on the mass of the object.” Perhaps you could create a sensor, and then use the collision event to invert the the linear/angular velocity and set linear/angular drag to get a buoyancy effect [import]uid: 49447 topic_id: 16060 reply_id: 59734[/import]

gravity and/or mass can not be changed in corona once the physical body is set.

otherwise you could do this rather easily :confused: [import]uid: 79135 topic_id: 16060 reply_id: 59745[/import]

OK. Still lost in the AS3 code as of now.

I’ve tried several (hundred it seems like) methods of implementing a buoyancy effect and I’ve come up with a little something which is closer than all my other attempts so far. The maths is not true to the AS3 example, it’s more of a hacked together simulation, but hey, I’m learning here after all…

The effect, surprisingly, is actually looking quite nice - probably much nicer than my inelegant code looks Ü

Anyway, I’m posting it below in an example that can be saved and run as a main.lua file - no other lua files or images are needed. I’d be grateful if people could have a look through my code and make any improvements that you can.

Specifically, the way I’ve coded it, it only contains one object that floats (named ‘box’). What if I wanted to add a 2nd box, and maybe a 3rd for example? How could I pass the object to the function? Can I do this somehow even though it’s called on enterFrame?

Anyway, without any more rambling, here is my code - no laughing please…Ü

[lua]
– IMPORT PHYSICS

local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 40 )

local gx, gy = physics.getGravity()

– FORWARD REFS

local _W = display.contentWidth

local _H = display.contentHeight

local ground, ceiling, leftWall, rightWall

local box

local waterLevel

– CREATE SCREEN BOUNDARY

ground = display.newRect(0,0,_W,20)
ground.x = _W * 0.5; ground.y = _H + (ground.height * 0.5)

ceiling = display.newRect(0,0,_W,20);
ceiling.x = _W * 0.5; ceiling.y = 0 - (ceiling.height * 0.5)

leftWall = display.newRect(0,0,10,_H)
leftWall.x = 0 - (leftWall.width * 0.5); leftWall.y = _H * 0.5

rightWall = display.newRect(0,0,10,_H)
rightWall.x = _W + (rightWall.width * 0.5); rightWall.y = _H * 0.5

physics.addBody(ground, “static”, {friction = 0.1})
physics.addBody(ceiling, “static”, {friction = 0.1})
physics.addBody(leftWall, “static”, {friction = 0.1})
physics.addBody(rightWall, “static”, {friction = 0.1})

– CREATE ‘BOX’

local box = display.newRect(_W * 0.5, _H * 0.5, 64, 64)
box.x = _W * 0.5; box.y = 64
box.area = box.height * box.width
box.density = 3.0
box.mass = box.area * box.density

physics.addBody( box, { density=3.0, friction=0.5 } )

– CREATE WATER

local water = display.newRect(0, 0, _W, _H * 0.5)

water:setFillColor(0, 102, 255)
water.alpha = 0.3
water:setReferencePoint(display.TopCenterReferencePoint)
water.x = _W * 0.5
water.y = _H * 0.5

– TOUCH TO DRAG FUNCTION

local function dragBody(e)
local body = e.target
local phase = e.phase
local stage = display.getCurrentStage()

if(phase == “began”) then

stage:setFocus(body, e.id)

body.isFocus = true
body.tempJoint = physics.newJoint(“touch”, body, e.x, e.y)

elseif(phase == “moved”) then

if(body.tempJoint ~= nil) then

body.tempJoint:setTarget(e.x, e.y)
end

elseif(phase == “ended” or phase == “cancelled”) then
if(body.tempJoint ~= nil) then
stage:setFocus(body, nil)

body.isFocus = false

body.tempJoint:removeSelf()
body.tempJoint = nil
end
end

return true
end

box:addEventListener(“touch”, dragBody)

– FLOAT/BUOYANCY FUNCTION

local function float()

if (box.y + (box.height * 0.5)) >= water.y then

local submergedPercent = math.floor (100 - (((water.y - box.y + (box.height * 0.5)) / box.height) * 100))

if submergedPercent > 100 then

submergedPercent = 100

end

if submergedPercent > 40 then

local buoyancyForce = (box.mass * gy)

box:applyForce( 0, buoyancyForce * -0.002, box.x, box.y )

box.linearDamping = 4

box.angularDamping = 5

else

box.linearDamping = 0

box.angularDamping = 0

end

end

end

Runtime:addEventListener( “enterFrame”, float )[/lua]
PS: I know the float object ‘bounces’ a little when settled on the water surface - that’s not too bad a thing as my water will be animated with a slight ripple wave to it anyway - feel free to clean it up though if you wish. [import]uid: 74503 topic_id: 16060 reply_id: 60083[/import]

You have a nice thing going there… it’s impressive

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16060 reply_id: 60109[/import]

@JayantV Thanks - Glad you like it and that I’m heading in the correct direction.

Anything, you think that you might alter? How about:

[‘Specifically, the way I’ve coded it, it only contains one object that floats (named ‘box’). What if I wanted to add a 2nd box, and maybe a 3rd for example? How could I pass the object to the function? Can I do this somehow even though it’s called on enterFrame?’]

Can this be done somehow? [import]uid: 74503 topic_id: 16060 reply_id: 60110[/import]

Hi
Did you saw this?
http://developer.anscamobile.com/forum/2011/03/30/liquid-surface-simulation [import]uid: 13156 topic_id: 16060 reply_id: 60111[/import]

@PiotrT,
That is nice, but can be used for fanciful fx only at this time.

@iNSERT.CODE

  1. If we do not apply the force, then the object will not stay in the air (i.e. will fall) so the constant application of force is required.

  2. You can modularise this code by having a loop that bobs each item you have added using a for loop, calling a function inside of enterFrame called bobBody(theBody, theMass) that way you can pass different objects to it

  3. I was having a look at making the body inactive or allowing it to sleep, but then it requires constant force to keep it up.

so when you create a new Body, add it to a table, in enterFrame call bobBody on each of the items in the table.

hope that makes sense,

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16060 reply_id: 60114[/import]

Hi,

I really liked your code sample as this is something I’ve been thinking/wondering/mulling for a while and your implementation is really good.

Personally, I don’t like using the enterFrame event as it very easily increases the chance of performance problems and often requires a lot more code to manage the operations taking place there. So I came up with the following modification of your code.

I’ve added a ball which can be thrown around, to affect the buoyant box, which is still draggable. The problem is that the box does not seem to have any friction against the ‘water’, so it’s rotation would need to be adjusted somehow - my answer to this would be another joint.

So, the core of my implementation is simply: Create an invisible anchor (off screen) to which other objects can be jointed to. Use this anchor to create a horizontal piston joint to limit a ‘lifting’ object. (Imagine a crane working at a port - it moves left and right and has a lifting platform which can move up and down.)

So, the lifter (moving along the piston) has a distance joint attaching it to the box. The distance joint is made rather springy, to mimic the fluidity of the water.

So, in short, I’ve tried to get buoyancy by using a distance joint which itself can move around, so that it is not always pulling the box back towards one fixed location.

I hope you like it - sorry for the overly long description…

Matt.
[lua]-- INIT PHYSICS
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 40 )

local gx, gy = physics.getGravity()
– FORWARD REFS
local _W = display.contentWidth
local _H = display.contentHeight
local ground, ceiling, leftWall, rightWall
local box
local waterLevel
– CREATE SCREEN BOUNDARY

ground = display.newRect(0,0,_W,20)
ground.x = _W * 0.5; ground.y = _H + (ground.height * 0.5)

ceiling = display.newRect(0,0,_W,20);
ceiling.x = _W * 0.5; ceiling.y = 0 - (ceiling.height * 0.5)

leftWall = display.newRect(0,0,10,_H)
leftWall.x = 0 - (leftWall.width * 0.5); leftWall.y = _H * 0.5

rightWall = display.newRect(0,0,10,_H)
rightWall.x = _W + (rightWall.width * 0.5); rightWall.y = _H * 0.5

physics.addBody(ground, “static”, {friction = 0.1})
physics.addBody(ceiling, “static”, {friction = 0.1})
physics.addBody(leftWall, “static”, {friction = 0.1})
physics.addBody(rightWall, “static”, {friction = 0.1})
– CREATE ‘BOX’

local box = display.newRect(_W * 0.5, _H * 0.5, 64, 64)
box.x = _W * 0.5; box.y = 64
box.area = box.height * box.width
box.density = 3.0
box.mass = box.area * box.density

physics.addBody( box, { density=3.0, friction=0.5 } )
box.y = display.contentCenterY
– CREATE WATER

local water = display.newRect(0, 0, _W, _H * 0.5)

water:setFillColor(0, 102, 255)
water.alpha = 0.3
water:setReferencePoint(display.TopCenterReferencePoint)
water.x = _W * 0.5
water.y = _H * 0.5

– *** START OF NEW CODE ***

– CREATE GLOBAL ANCHOR
local anchor = display.newCircle( -100, -100, 10 )
physics.addBody( anchor, “static”, { friction=0, density=0, radius=10, bounce=0 } )

– CREATE LIFTING ANCHOR
local lift = display.newCircle( box.x, 10, 10 )
physics.addBody( lift, “dynamic”, { friction=0, density=1, radius=10, bounce=0 } )
– CREATE JOINT TO BOY THE BOX IN THE WATER
–local myJoint = physics.newJoint( “piston”, anchor, box, anchor.x,display.contentCenterY, 5,0 )

– CREATE JOINT HOLDING THE LIFT
local piston = physics.newJoint( “piston”, anchor, lift, anchor.x,anchor.y, 5,0 )

– CREATE JOINT HOLDING THE BOX BY THE LIFT
local distance = physics.newJoint( “distance”, lift, box, lift.x,lift.y , box.x,box.y )
–distance.length = box.y - lift.y
distance.dampingRatio = 100
distance.frequency = 8
print(distance.length…’ ‘…distance.frequency…’ '…distance.dampingRatio)

– CREATE THROWABLE BALL

local ball = display.newCircle( box.x,100,20 )
physics.addBody( ball, “dynamic”, { friction=1,bounce=0,density=3,radius=20 } )

– *** END OF NEW CODE ***

– TOUCH TO DRAG FUNCTION

local function dragBody(e)
local body = e.target
local phase = e.phase
local stage = display.getCurrentStage()

if(phase == “began”) then
stage:setFocus(body, e.id)
body.isFocus = true
body.tempJoint = physics.newJoint(“touch”, body, e.x, e.y)
elseif(phase == “moved”) then
if(body.tempJoint ~= nil) then
body.tempJoint:setTarget(e.x, e.y)
end
elseif(phase == “ended” or phase == “cancelled”) then
if(body.tempJoint ~= nil) then
stage:setFocus(body, nil)
body.isFocus = false
body.tempJoint:removeSelf()
body.tempJoint = nil
end
end

return true
end
box:addEventListener(“touch”, dragBody)
ball:addEventListener(“touch”, dragBody) — *** NEW ***

– FLOAT/BUOYANCY FUNCTION

local function float()
if (box.y + (box.height * 0.5)) >= water.y then
local submergedPercent = math.floor (100 - (((water.y - box.y + (box.height * 0.5)) / box.height) * 100))
if submergedPercent > 100 then
submergedPercent = 100
end

if submergedPercent > 40 then
local buoyancyForce = (box.mass * gy)
box:applyForce( 0, buoyancyForce * -0.002, box.x, box.y )
box.linearDamping = 4
box.angularDamping = 5
else
box.linearDamping = 0
box.angularDamping = 0
end
end
end

–Runtime:addEventListener( “enterFrame”, float ) – *** COMMENTED OUT ***[/lua]
[import]uid: 8271 topic_id: 16060 reply_id: 60127[/import]

This one’s going to be a long post… :wink:

http://www.youtube.com/watch?v=0uX-1GXYIss

http://www.patrickmatte.com/stuff/physicsLiquid/

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16060 reply_id: 60133[/import]

@horacebury - I tried a similar technique using joints too. The bobbing effect is nice still, but perhaps a little too ‘springy’.

The downside to that implementation is also that you can get some unnatural/unexpected results when manoeuvring the floating objects. For example, if you try dragging the box all the way to the bottom of the water and then let go (straight down to up), you’ll see it shoot off to the side after it’s left the water - despite having no sideways force ever having been applied. Same thing happens if you throw the box towards the top of the screen (towards anchor/lift).

Therefore, if as in my game, objects need to go in and out of the water frequently, then this wouldn’t be a feasible solution as it is.
@jayant - I have seen (and bookmarked) those links whilst on my quest for a solution. With regards to the bootle example, are those BitmapData features available in Corona SDK? Also, for the YouTube vid, I actually saw that embedded on some forum somewhere when searching Google for the buoyancy inspiration - someone was asking how it’s done. I think that forum linked to the AS3 example that I originally posted stating that that is how it was achieved.

Thanks for the tips on how to add multiple boxes using a table and passing the object to the enterFrame using bobBody(theBody, theMass). I’m not quite sure exactly how to implement this though. Passing objects and parameters, especially from a table is something that I’m not yet 100% on. If you can spare any free time at all, perhaps, you could make a quick modification to my original code and demonstrate how it’s done for me? It’d be a great way for me to learn how to modularise something like this and I’d be very grateful. We could perhaps then add this to the Code Share.

If not, then not to worry though - I know everyone’s busy with their own projects etc.
Thanks again all, and keep any suggestions coming. [import]uid: 74503 topic_id: 16060 reply_id: 60141[/import]

Yep, I totally agree. Grabbing the box with the touch joint showed the same effect if you drag it out of the water. I think it’s a simple physics engine related issue which can be engineered around. I take your point though. Of course, the distance joint doesn’t make the object act like it is submerged, though I quite liked the bobbing effect.

Also, in answer to your request about multiple boxes, I’ve modified your original code to have those…

[lua]-- INIT PHYSICS
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 40 )

local gx, gy = physics.getGravity()
– FORWARD REFS
local _W = display.contentWidth
local _H = display.contentHeight
local ground, ceiling, leftWall, rightWall
local box
local waterLevel
– CREATE SCREEN BOUNDARY

ground = display.newRect(0,0,_W,20)
ground.x = _W * 0.5; ground.y = _H + (ground.height * 0.5)

ceiling = display.newRect(0,0,_W,20);
ceiling.x = _W * 0.5; ceiling.y = 0 - (ceiling.height * 0.5)

leftWall = display.newRect(0,0,10,_H)
leftWall.x = 0 - (leftWall.width * 0.5); leftWall.y = _H * 0.5

rightWall = display.newRect(0,0,10,_H)
rightWall.x = _W + (rightWall.width * 0.5); rightWall.y = _H * 0.5

physics.addBody(ground, “static”, {friction = 0.1})
physics.addBody(ceiling, “static”, {friction = 0.1})
physics.addBody(leftWall, “static”, {friction = 0.1})
physics.addBody(rightWall, “static”, {friction = 0.1})
– CREATE ‘BOX’

– a display group we can loop through
– works just like a table, but allows us to perform other display functions upon the boxes as well
– just be sure to use boxes.numChildren instead of #boxes when getting the number of boxes in the group
– but otherwise it works just like a table (which is really just an array)
local boxes = display.newGroup()
– call this to create a single box
– it adds that boxs to the ‘boxes’ display group
function addBox()
local box = display.newRect( boxes, _W * 0.5, _H * 0.5, 64, 64)

box.x = _W * 0.5; box.y = 64
box.area = box.height * box.width
box.density = 3.0
box.mass = box.area * box.density

box:setFillColor( math.random(100,255), math.random(100,255), math.random(100,255) )

physics.addBody( box, { density=3.0, friction=0.5 } )
box.y = display.contentCenterY
end
– CREATE 5 BOXES BY DEFAULT, just change the number ‘5’ to any positive integer
for i=1, 5 do
addBox()
end
– CREATE WATER

local water = display.newRect(0, 0, _W, _H * 0.5)

water:setFillColor(0, 102, 255)
water.alpha = 0.3
water:setReferencePoint(display.TopCenterReferencePoint)
water.x = _W * 0.5
water.y = _H * 0.5

– TOUCH TO DRAG FUNCTION

local function dragBody(e)
local body = e.target
local phase = e.phase
local stage = display.getCurrentStage()

if(phase == “began”) then
stage:setFocus(body, e.id)
body.isFocus = true
body.tempJoint = physics.newJoint(“touch”, body, e.x, e.y)
elseif(phase == “moved”) then
if(body.tempJoint ~= nil) then
body.tempJoint:setTarget(e.x, e.y)
end
elseif(phase == “ended” or phase == “cancelled”) then
if(body.tempJoint ~= nil) then
stage:setFocus(body, nil)
body.isFocus = false
body.tempJoint:removeSelf()
body.tempJoint = nil
end
end

return true
end

– LOOP TO CREATE MULTIPLE BOXES
for i=1, boxes.numChildren do
boxes[i]:addEventListener(“touch”, dragBody)
end

– FLOAT/BUOYANCY FUNCTION

local function float()
for i=1, boxes.numChildren do – LOOP TO APPLY FORCES TO EACH BOX INDIVIDUALLY
– get the box from the display group
local box = boxes[i]

– apply forces to box
if (box.y + (box.height * 0.5)) >= water.y then
local submergedPercent = math.floor (100 - (((water.y - box.y + (box.height * 0.5)) / box.height) * 100))
if submergedPercent > 100 then
submergedPercent = 100
end

if submergedPercent > 40 then
local buoyancyForce = (box.mass * gy)
box:applyForce( 0, buoyancyForce * -0.002, box.x, box.y )
box.linearDamping = 4
box.angularDamping = 5
else
box.linearDamping = 0
box.angularDamping = 0
end
end
end
end

Runtime:addEventListener( “enterFrame”, float )[/lua] [import]uid: 8271 topic_id: 16060 reply_id: 60155[/import]

That’s some nice looping right there. I’ve altered the code a little once again to randomise the starting position of the boxes.

I’m really happy with the result of this I think. It will look realistic in a game and that’s what counts - I’d be happy to implement it and it’s flexible enough that others can too.

Do you think other’s would benefit from this, and if so, is it something that I can/should upload to the Code Share section to make it more visible/easier for people to locate? If so, I’m more than willing to post and share it there. [import]uid: 74503 topic_id: 16060 reply_id: 60193[/import]

Definitely. I think if you modularise it, a small learning curve but worth it, it’ll be more useful.

Personally, I’d loveto use it. My interest would be in getting it easily usable by existing components of my game. Perhaps if it loops over a given display group or even just accepts a table of display groups. That way the objects in the water don’t have to be restricted to one group and your code doesn’t have to do any maintainence itself. Also, it will need control functions, like it, start, stop, various forc etc. If it could be applied to multiple fluid bodies that would be good too.

Perhaps play with collision detection? If it affects every object colliding with a given sensor body with the properties of the fluid defined in a table attached to that body it would greatly simplify configuration of multiple bodies and allow them to change after creation. One of the complaints of physics bodies is that once their density, for example, is set it can’t be changed. Your code should not ha e that restriction.

Good luck.

M [import]uid: 8271 topic_id: 16060 reply_id: 60198[/import]

Thanks, I’ll look into all that then. I have made a few modifications to the code already. Specifically, I’ve added a ‘Settings’ section that allows simple changing of:

  • Number of Boxes

  • Box Size

  • Liquid Density

The liquid density allows the user to control how viscous the liquid is. The default setting of 1.0 simulates water, and the higher the number, the more viscous the fluid becomes. A setting of 2.5 here simulates something similar to oil etc.

The last thing you mentioned was that one of the complaints of physics bodies is that once their density is set it can’t be changed. I agree with this completely. Actually, if you look closely at my original code (and all the revisions), the ability to change the density of the boxes is already present.

I achieved this by making my calculations using ‘box.mass’, which itself is calculated by multiplying ‘box.area’ and ‘box.density’ together. ‘box.density’ is a variable object property that I set at 3.0, but this is only used for the calculations for the effect of buoyancy in the liquid. This can be changed without affecting the actual density of the box for physical collisions with other physics bodies. That said, the way the calculation is, it currently works in the reverse of what you would expect.

i.e. Setting it to a lower value makes the box appear heavier in the water and the higher the number makes it lighter. 1.0 would make it sink for example, and 4.0 would make it rise to the surface quicker.

Anyway, I mentioned at the beginning of this thread that I am currently working on a game (my first in fact) which unexpectedly has led me down this long, but productive detour of a road. For that reason, and because I am new to programming (about 6 weeks in), implementing the other changes to modularise this may take me a little longer as I’ll have to learn how to do it.

With this working example though, I can finish off the final stages of my project. So here’s what I plan to do. I will be uploading this to the code share with a description, and host the downloadable main.lua file on my web server so that people can click to download it as it is. That will mean that I can make the changes that you have suggested in further revisions as soon as I get a little time to research and implement it.

I’ll definitely find the time to complete this, as it will be a great way for me to learn and I’m very happy to share what I can with the community. As a newbie, it gives me confidence that I can produce code that is at the very least, legible, and possibly even useful to others.

Thanks again for your input - and apologies for the seriously long post

[import]uid: 74503 topic_id: 16060 reply_id: 60247[/import]

I have to say that I extremely interested in this code and would really like to use it in my next game - you’ve done some great work here!

If you could post, here, the latest version I will modularise it and perhaps a few other things you’ll find useful, hopefully short cutting some of the work you might have to.

Thanks for the big effort :slight_smile:

M [import]uid: 8271 topic_id: 16060 reply_id: 60326[/import]

Sounds great. Any help is much appreciated and will help me out personally a great deal.

I’ve actually done what I said in the post above, and last night I posted it in the Code Share here:

http://developer.anscamobile.com/code/water-buoyancy-example

I’ve mentioned/credited you on both my web site where the file is hosted, and in the actual main.lua file itself.

If you can do anything with regards to modularising it, then I’ll upload the revision and explain that you’ve modularised it.

Also, if you do use this in your game, then post me a link and I’ll blog about it a post a link back to it in iTunes and/or your web site.

If you want, you can email me the revised main.lua at

contact
@
insertcode.co.uk [import]uid: 74503 topic_id: 16060 reply_id: 60348[/import]

I take back what I said earlier, that is very cool. [import]uid: 79135 topic_id: 16060 reply_id: 60436[/import]