Creating my own physics behavior, need info

For developers using the Construct 2 Javascript SDK

Post » Sun Sep 11, 2016 12:27 pm

Hi,
I don't know anything about behavior development.

I need to create a copy of the default physics behavior with my own settings (just lowering b2_velocityThreshold actually)

What's the difference between runtime.js and runtime-ams.js in this directory? The behavior seems not to be using runtime.js as deleting this file won't cause the behavior to crash.
Plus, runtime-ams.js is twice runtime.js size though it contains some sort of minified javascript.
If I replace runtime-ams.js content with runtime.js content, the behavior seems still working though the file is half the original size.

Can you explain me what's going on here?

What would be the best method in order to make my own copy of this behavior?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sun Sep 11, 2016 2:43 pm

Typically there is only a runtime and edittime js. The physics behavior Is special case. One is just a JavaScript port of box2d and one is one compiled with asm.js. It's bigger but will run near native c++ performance. You can select between the two in the project properties.

If you were to copy the behavior just pick either file to be your runtime.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Sun Sep 11, 2016 3:13 pm

Thank you very much for this explanation. :)

So I guess the simplest way is to duplicate the physics behavior?
There is no way to edit this b2_velocityThreshold value inside C2 via a custom plugin or something like that?

The things that bother me is that I'll have to add my new custom physics behavior to all my objects and then edit all my conditions and events referring to the physics behavior to replace them with the other behavior conditions & events.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sun Sep 11, 2016 5:20 pm

You could just edit in in place if it's something just you would use. If you want to change it per project the best thing would be to add an action to the plugin. That would give the easiest access to the setting.

I guess it may be possible to change the setting with some JavaScript run with the browser object. That can be hard though, mainly to track down a code path to access it. It would also not work if you minified your project.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Sun Sep 11, 2016 7:13 pm

If you use "box2d web" instead of "box2d asm.js" you can use the browser object to run:
"Box2D.Common.b2Settings.b2_velocityThreshold = 1.0;"
and set it to whatever value you want. The asm.js version seems to not have that variable. This won't work after minifying.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Sun Sep 11, 2016 9:15 pm

Thanks again for these useful information :)
Since my game won't use a lot of physical objects, I guess I can stick to box2d web.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests