Physics: the rest of box2d

0 favourites
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • I am adding features as I need them to the physics behavior. Unfortunately, The current organization and terminology used by the vanilla physics behavior doesn't make additions of other features as intuitive (Static, dynamic, and kinematic) as it could be. which means the new behavior won't work with your old physics projects. ( of course, if the behavior got updated by construct it would break newer projects, so its a trade off)

    If anyone is interested in the results, let me know. It may be that Ashley will be adding these soon, but I can't wait any longer.

    Currently, I have added prismatic joints, and kinematic bodies and a few other things. I will be adding edge shapes, an edge shape plugin to make it easy to add collision geometry to a level, and pre collision callbacks and contact information.

    I can share the code needed to make changes, which is probably more useful as you could make it work with older projects as well. Most features only take a few lines of code here and there.

  • I feel like I might give it a shot if this next release cycle doesn't add any more physics features. But until then, it kinda seems like jumping the gun, so to speak, since this next release cycle does in fact seem to be related to expanding or at least developing the physics a bit more.

  • How did I miss this?!? Ruskul, this could save me a lot of stress... Any code or tips you could share would be much appreciated - thanks for looking at this.

  • Ruskul

    Sounds interesting.

  • It would be nice to have more options !

  • Colludium - is there any thing in particular that you need?

    I found a bug in the ams.js version that I can't fix, I haven't heard back from from the original transcriber (c++ to ams.js) and am currently helpless to solve the issue. I actually was responsible for getting the code to fix the bug for friction contacts not being updated, which helped me learn alot about c2, box2d, and ams.js... I tried using box2dweb, but it is a very old version of box2d and lacks the ability to update contacts after changing friction. Long story short, I need some features I can't access in ams.js but I also need contact updating. Basically, neither physics behaviors allow me to do what I need.

    Consequently, I searched for other javascript versions of box2d but the above choices are the best choices. Which means I am no longer using c2 to work on my main game project, I have switched over to unity, which already has the physics I need without having to muck about chasing bugs.

    However, I would be happy to help get you what you need in physics if it is doable. I can say right now that I can't do preCollision or PostCollision checks in ams.js , and that I can't update contacts in box2dweb.

    I can however do things like, make a body kinematic, add a prismatic joint, and so on. I could add collision filtering, but the disable collisions between two objects works in ams.js now by defualt. Also, Ashley may add some more features soon, who knows. He did say a year ago that he wouldn't until ams.js updated, which it is, so here we are.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ruskul - you're a gent. To be honest, I'm not sure if I want to commit to trying to create more features by editing the physics plugin since it seems like you've already done the work and found problems trying to do the same (I am javascript level zero, by the way...), but it's very kind of you to offer to help! I am primarily interested in creating kinematic bodies - I have a poor-man's work-around involving moving immovable objects using events, but they don't collide nicely with other physics objects unless they are limited to moving very slowly. I should probably start another thread rather than hijack this one! I've experimented a bit with r0j0's chipmunk plugin but the joints seems slightly less stable, IMO, and I was hoping that asm.js might produce the goods in time for me to complete what I'm doing.... I'm probably being picky and should give that another go, even though it would mean I have to start again on my current project.

  • Colludium - I can help you here. There is no problem that I have found in ams.js with kinematic bodies, so that should work great.

    What I can do for you is send you the code needed for runtime and edittime. You can simply copy and paste it into the stock behavior, or you can copy the stock behavior, rename it something else so you get no conflicts, and then paste it. Each has it's pros and cons. (I can tell you if you don't know what they are).

    I could also just do this myself and then pass you the behavior. You would just have to copy it to the correct file location.

    I won't provide you with a property you can toggle in the editor, because... its complicated. Its not a problem to do, but if I do it in a meaningful way, you won't be able to have it with the stock behavior as it would break existing projects. If you don't care to incorporate this with an existing project, I can add the toggle but it takes more "work" and it's not as easy to add to subsequent releases of physics.

    Any object that you want to be kinematic from the getgo, you simply do: OnStart of Layout - Physics: setBody Kinematic.

    It may seem complex but I promise, its not. I used to use the workaround you mentioned but you are right, velocity and stuff doesn't work right. and then I realized, box2d is really straightforward to work with. The hard part of adding it is, knowing javascript and understanding the construct 2 sdk. I originally added it without understanding any of the last two, lol. I have since learned javascript (I still don't like it compared to the C languages) and the sdk, so hopefully I won't be adding a subtle bug (:

    Let me know if you have any questions and the format you want the code in.

  • Ruskul, that would be awesome! Any format I can use would be great - NP++ is my friend and I would like to learn how to edit a behavior - it sounds like the perfect time to start!

    I have mixed feelings about editing the stock behavior because there's: a) a small burden of re-updating it after each c2 update, and b) it's possible that Ashley might one day provide us with more than a light version of box2d. However, I have no problem with setting parameters using event sheets, so that is what I would like - the code to copy / paste into the stock behavior. I really appreciate the help - thank you!!

    Also, while I think about it, do you know a way to add joints / apply forces / apply impulses to an object using real world coordinates, rather than just via imagepoints? Thanks again!

  • Colludium , Okay, I'll send the code in the next few days when I get time to do it. (probably tonight). Let me think on the joint/force/ stuff. I can't recall how box2d handles this. I know you can apply a force at anyposition though... (I think it is defined in local coordinates though).

  • Ruskul - thank you very much indeed!!

  • Colludium - Here is the code that can be inserted into the vanilla behaviors. If you don't understand anything let me know.

    To start with, locate the behavior file "Physics". You should make a copy of this folder someplace safe so if you mess anything up you can restore it without reinstalling construct.

    You can use this code to modify either ams.js physics or box2dweb physics. Either way, you need to open up both the edittime.js file and the runtime file (or both runtime files if you want the changes available in both physics engines).

    You need to add this line of code to the actions are in the edit time file. This creates an action that can be used in the construct 2 editor:

    AddAction(28, af_none, "Set body to Kinematic", "Object Settings", "Set {my} Kinematic", "Set this object to be a Kinematic body.", "SetKinematic");

    This goes in at around line 195. Do you see the first parameter in the AddAction call. Currently it is set to 28. This number has to be unique. If Ashley updates physics and you have this attached to the vanilla behavior and have to re add it, you may have to change that number (you can tell by looking at the last AddAction call and see what number it is using. In my case, this number was 27.

    After that, add the following to the runtime:

    Acts.prototype.SetKinematic = function (k)

    {

    if (!this.enabled)

    return;

    this.body.SetType(1);

    this.body.SetAwake(true);

    };

    I added to where all the other Actions are (denoted by "Acts.prototype...."). You can find it easier by typing "cntr + f" to find it. The physics behavior is 13,000 lines of code, so reading through it to find where to put it can take a while. (it is at the very bottom though, right above exps.prototype.... for the expressions.

    and that's it!

    If you want to create your own behavior instead of modifying the existing one, you should copy the whole physics folder, rename the folder what you want the new behavior to be called and then change the top lines in the edittime file to reflect the new name. Replace the name with your new name (as you want it to appear in construct) and then replace the ID. I know it says never change it, but as you are making a new behavior, you need to change it to be something unique, else construct will think the vanilla physics and this new one are the same thing and then you will have problems

    Let me know if it all works out!

    stupid simple... Its like 5 lines of code. I never understood why this wasn't included in the behavior >.>

  • Ruskul - I owe you one - thank you very much!!

    Edit to add: I don't understand why this has not been done already!!!!!!!!!!!!!!!!!

  • Colludium - did you get it working?

  • Ruskul - yes!! That was far too easy, LOL! I was distracted by trying to create an artifact-free trailer for this. I really appreciate the time you took to figure this out - it's going to prove very very useful. Cheers!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)