Help Fleshing out one of the Tutorials

Besides the math, the big change was to the style of listener.

See here for more on listener styles/types:

https://docs.coronalabs.com/guide/events/detectEvents/index.html#local-events

This may actually still be confusing to you.

@everyone - If somone else remembers where the full tutorial on listeners is, please share the link here.

vec = ssk.math2d.scale( vec, forceMag \* self.mass )

Where is mass coming from? Is it part of the physics radius?

Mass is an integral value to the body  based on its square area and density.

You can change density and the default is 1.

If you don’t use mass in your force and impulse equations and later you change the size of the object, the behavior will change because the mass will increase or decrease.  Thus, to keep the results you tune in, use mass as a factor in your equations as I have.

Where can I read about placing constraints on the screen. I was thinking about placing Walls but that seems inefficient. So that the balloon doesn’t go out of the screen to the left and right.

@asleeprj

You can also use trigonometry to set the forceX, and forceY of the linear impulse.  For whatever reason, I ended up using trig instead of vectors for all of my physics calculations.  I haven’t compared the two in a while, but my general impression is that vectors (primarily being angle-based) are a faster, cleaner and more efficient for position and motion calculation but trig (being circle-based) has a more nuanced feel that I like for my systems which are more biological rather than vehicular.  

I’ve adjusted @roaminggamer’s code for a trig application below.

In the near future you will want to explore linear and angular damping in the physics object properties section

[lua]

local function getAngle ( o, t, inRadians )

     local inRadians = inRadians or false

     if (inRadians == true) then

          local radians = math.atan2(t.y - o.y, t.x - o.x)

          return radians – radian - atan2 adjusts or quadrant

     elseif (inRadians == false) then

          local degrees = math.deg( math.atan2(t.y - o.y, t.x - o.x) )

          return degrees  – degrees - atan2 adjusts or quadrant

     end

end

function balloon.tap( self, event )

     local forceFactor = self.mass * 1000 – adjust as needed

     local angle = getAngle(self, event, true) – get angle returned in radians

     local forceX = math.cos(angle) * forceFactor

     local forceY = math.sin(angle) * forceFactor

     self:applyLinearImpulse( forceX, forceY, self.x, self.y )

end

balloon:addEventListener(“tap”)

[/lua]