Possible physics additions/feature request

I’ve been following a buoyancy box2d tutorial (on C++) implementing it on Corona and things were going great, some small hiccups but found workarounds for them. But now my progress is completely blocked, since we don’t have access to the GetLinearVelocityFromWorldPoint or GetLinearVelocityFromLocalPoint functions.

Could it be possible to get these 2 functions for physics bodies? Also, there is a setter physics.setScale() function, but there is no getter function for the scale, which is also needed in order to find the displaced mass. (I know it is 30 by default, but if this value changes, we need a way of getting it back)

You can see my progress for buoyancy in this video.

I’ve made a feature request, you can vote for it here.

I have implemented that particular code in Lua before we have the LiquidFun feature and you can use the .linearVelocity property on your physics bodies. I don’t think you need to, however, as with LiquidFun you can just create water and drop your object into it.

Sensors are way more convenient than particles. I don’t have to create a pool to contain leaks, for example. It is not for aesthetics, it is for the game mechanic itself. I can also phase and move a sensor around on top of any other physics object. Imagine for example, draining a pool, just transition the water sensor height, y, and voila, no removing particles or any complex plumbing.

I know i can use .getLinearVelocity, but it does not yield the same results as the local or global one. For example, an object could be rotating and linear velocity varies throughout the body. 

I doubt you completely recreated the buoyancy tutorial, with advanced drag and lift, exactly as in the video, without one of those 2 functions. if not, i would very much like to see your code in action.

Not exactly, but close enough. I found a better way was to effectively cheat and use a different method in the end.

I think the LiquidFun solution is pretty easy to implement and will give you realistic motion. Without those extra values you can always attach an invisible sensor to the location on the object you want the value from and get the value from that.

Otherwise, create a feature request: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback

I created the feature request since the first post.

Anyway, how hard can it be to add an already existing function on Box2D to Corona? I know the bridge is already in place. Same for the scale. An already passed in value, which is already stored somewhere, how hard can it be to make a getter? It’s as if they thought “Corona SDK Devs are never gonna use this, let’s just not include it.”

Hell, we could even add an x and y parameter to the existing .getLinearVelocity function. No parameters = normal behavior, parameters = velocity on local position.

I know the physics.* wrapper is there in place in order to make development faster, you save a ton of lines to not make a world, manually update it and other stuff, but to make advanced stuff like this, it can sometimes lack the full potential that the underlying tech has (In this case Box2D).

Don’t get me wrong, i love Corona, I’m glad we have other powerful stuff like custom shaders, and an extending library of tools in the marketplace. I’m just asking for the physics library to get some love.

Thinking back a long way, I did at some point create a buoyancy demo which used an array of sensor objects to determine where on an object force values should be applied. It was very simple, really… Just have tiny, equally spaced sensor dots throughout the “water” area and if they come into contact with something deemed to be “in the water” then just add that object to a list. Once every (e.g.) 100 milliseconds loop through the list and for each sensor run through it’s list of contacted objects and apply a force directly upward. As with any physics simulation this had the downside that it could take a lot of processing, but balanced correctly it actually worked very well and got around the lack of linear velocity functions. It was shown in one of the Corona Geek sessions but it’s so long ago now I don’t know which one.

@horacebury lots of sensors with lots of lists and lots of listeners sounds very expensive. I already accomplished realistic buoyancy with any polygon shape sensors and any polygon shape bodies, with only one listener and one list per custom sensor. 

You can see the result in this short video (again) here.

The part i am missing is realistic drag and realistic lift, like how a boat lifts above the water because of its shape. Did you see the tutorial video i am trying to follow? This topic starts at the 2 minute mark.

Lately I’ve been feeling like no one reads the whole topic in these forums. 

I was just posting a thought as I noticed the thread in the recently read list. I wasn’t trying to provide a solution or an answer to the entire thread.

I think what you’ve got in your demo video is very impressive. I agreed it would be very good if more functions were added to physics bodies. Now you’ve added the future request maybe it will happen.

I have implemented that particular code in Lua before we have the LiquidFun feature and you can use the .linearVelocity property on your physics bodies. I don’t think you need to, however, as with LiquidFun you can just create water and drop your object into it.

Sensors are way more convenient than particles. I don’t have to create a pool to contain leaks, for example. It is not for aesthetics, it is for the game mechanic itself. I can also phase and move a sensor around on top of any other physics object. Imagine for example, draining a pool, just transition the water sensor height, y, and voila, no removing particles or any complex plumbing.

I know i can use .getLinearVelocity, but it does not yield the same results as the local or global one. For example, an object could be rotating and linear velocity varies throughout the body. 

I doubt you completely recreated the buoyancy tutorial, with advanced drag and lift, exactly as in the video, without one of those 2 functions. if not, i would very much like to see your code in action.

Not exactly, but close enough. I found a better way was to effectively cheat and use a different method in the end.

I think the LiquidFun solution is pretty easy to implement and will give you realistic motion. Without those extra values you can always attach an invisible sensor to the location on the object you want the value from and get the value from that.

Otherwise, create a feature request: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback

I created the feature request since the first post.

Anyway, how hard can it be to add an already existing function on Box2D to Corona? I know the bridge is already in place. Same for the scale. An already passed in value, which is already stored somewhere, how hard can it be to make a getter? It’s as if they thought “Corona SDK Devs are never gonna use this, let’s just not include it.”

Hell, we could even add an x and y parameter to the existing .getLinearVelocity function. No parameters = normal behavior, parameters = velocity on local position.

I know the physics.* wrapper is there in place in order to make development faster, you save a ton of lines to not make a world, manually update it and other stuff, but to make advanced stuff like this, it can sometimes lack the full potential that the underlying tech has (In this case Box2D).

Don’t get me wrong, i love Corona, I’m glad we have other powerful stuff like custom shaders, and an extending library of tools in the marketplace. I’m just asking for the physics library to get some love.

Thinking back a long way, I did at some point create a buoyancy demo which used an array of sensor objects to determine where on an object force values should be applied. It was very simple, really… Just have tiny, equally spaced sensor dots throughout the “water” area and if they come into contact with something deemed to be “in the water” then just add that object to a list. Once every (e.g.) 100 milliseconds loop through the list and for each sensor run through it’s list of contacted objects and apply a force directly upward. As with any physics simulation this had the downside that it could take a lot of processing, but balanced correctly it actually worked very well and got around the lack of linear velocity functions. It was shown in one of the Corona Geek sessions but it’s so long ago now I don’t know which one.

@horacebury lots of sensors with lots of lists and lots of listeners sounds very expensive. I already accomplished realistic buoyancy with any polygon shape sensors and any polygon shape bodies, with only one listener and one list per custom sensor. 

You can see the result in this short video (again) here.

The part i am missing is realistic drag and realistic lift, like how a boat lifts above the water because of its shape. Did you see the tutorial video i am trying to follow? This topic starts at the 2 minute mark.

Lately I’ve been feeling like no one reads the whole topic in these forums. 

I was just posting a thought as I noticed the thread in the recently read list. I wasn’t trying to provide a solution or an answer to the entire thread.

I think what you’ve got in your demo video is very impressive. I agreed it would be very good if more functions were added to physics bodies. Now you’ve added the future request maybe it will happen.

Hello!
Maybe so late, but I want to inform you that these methods have been added since Solar2D version 2023.3700. Include:

  • body:getWorldVector(x, y) – Get the world coordinates of a vector given the local coordinates.
  • body:getInertia() – Get the rotational inertia of the body about the local origin.
  • body:getLinearVelocityFromWorldPoint(worldX, worldY) – Get the world linear velocity of a world point attached to this body.
  • body:getLinearVelocityFromLocalPoint(localX, localY) – Get the world velocity of a local point.