Help! Physics with Storyboard

Hi!

I am developing an application where I work with storyboard and physics. I wish I knew how to put the physics in the storyboard. How to put in createScene, or enterScene, how to eliminate, which to declare physical objects and joints … is very important …

currently I am doing

Local physics = require (“physics”)

the declaration of bodies and joints in createScene

and then the enterScene the physics.start ()

exitScene in the physics.stop (), and also purgeScene …

go to the next scene, return to this, try to go back to the following, and then the application crashes

this is very important …

Grateful if anyone can help …

Thank you,

Tiago Eirinha

Hi @Tiago Eirinha,

Where are you placing your “local physics = require( “physics” )” line? This shouldn’t be inside any of the Storyboard event blocks, since anything related to physics will need this library reference.

Brent

Hi!

The “Require” is made ​​out of blocks of “storyboard” …

I, now, until I opted for a new way … But still the same …

I declared “local physics = nil” out of the blocks the storyboard …

In addition, I created a function, also out of the blocks the storyboard, designated “loadPhysics”:

[lua]local function loadPhysics()
physics = require(“physics”)
physics.start()
physics.pause()
end[/lua]

After this function is called in createScene, and “physics.start ()” in enterScene and “physics.stop ()” in exitScene. Furthermore, the removal of make library “physics” in destroyScene. Continuing to call the “storyboard.purgeScene ()” and “storyboard.removeAll ()” in exitScene.

I’ve been to separate the code and which gives problems is in the declaration of a “joint” … Physical objects with no problem … But when I declare one “joint”, alternate several times between the actual scene and another scene, crashes …

Another question: can you explain me in your own words, what does “physics.setContinuous (true / false)”?

Thanks for the time available,

Greetings,

Tiago Eirinha

Hi Tiago,

I would suggest that you avoid the “function” setup of physics. In each scene where you do physics operations, do a “local physics = require( “physics” )” near the top, outside of the Storyboard blocks.

Also, if you use physics in most scenes, you probably don’t need to “.stop” the physics engine. Pausing it should be enough.

For “physics.setContinuous()”, it basically turns off “constant” collision sensing in the engine. If you turn it off (false), then some fast-moving objects may pass through other objects. Unless you have a very specific need, I recommend that you leave it turned on (default).

Brent

Hi @Tiago Eirinha,

Where are you placing your “local physics = require( “physics” )” line? This shouldn’t be inside any of the Storyboard event blocks, since anything related to physics will need this library reference.

Brent

Hi!

The “Require” is made ​​out of blocks of “storyboard” …

I, now, until I opted for a new way … But still the same …

I declared “local physics = nil” out of the blocks the storyboard …

In addition, I created a function, also out of the blocks the storyboard, designated “loadPhysics”:

[lua]local function loadPhysics()
physics = require(“physics”)
physics.start()
physics.pause()
end[/lua]

After this function is called in createScene, and “physics.start ()” in enterScene and “physics.stop ()” in exitScene. Furthermore, the removal of make library “physics” in destroyScene. Continuing to call the “storyboard.purgeScene ()” and “storyboard.removeAll ()” in exitScene.

I’ve been to separate the code and which gives problems is in the declaration of a “joint” … Physical objects with no problem … But when I declare one “joint”, alternate several times between the actual scene and another scene, crashes …

Another question: can you explain me in your own words, what does “physics.setContinuous (true / false)”?

Thanks for the time available,

Greetings,

Tiago Eirinha

Hi Tiago,

I would suggest that you avoid the “function” setup of physics. In each scene where you do physics operations, do a “local physics = require( “physics” )” near the top, outside of the Storyboard blocks.

Also, if you use physics in most scenes, you probably don’t need to “.stop” the physics engine. Pausing it should be enough.

For “physics.setContinuous()”, it basically turns off “constant” collision sensing in the engine. If you turn it off (false), then some fast-moving objects may pass through other objects. Unless you have a very specific need, I recommend that you leave it turned on (default).

Brent