Physics: the rest of box2d

Post your work in progress addons and get feedback

Post » Tue Feb 10, 2015 11:14 pm

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.
You do not have the required permissions to view the files attached to this post.
Last edited by ruskul on Thu Feb 12, 2015 7:45 am, edited 2 times in total.
Image
B
32
S
11
G
2
Posts: 563
Reputation: 5,106

Post » Wed Feb 11, 2015 3:16 am

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.
ImageImageImageImage
B
57
S
19
G
51
Posts: 633
Reputation: 30,681

Post » Sat Mar 14, 2015 11:27 am

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.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
69
S
18
G
65
Posts: 2,195
Reputation: 41,465

Post » Sat Mar 14, 2015 2:38 pm

@ruskul

Sounds interesting.
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Sat Mar 14, 2015 3:17 pm

It would be nice to have more options !
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Mar 14, 2015 6:24 pm

@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.
Image
B
32
S
11
G
2
Posts: 563
Reputation: 5,106

Post » Sat Mar 14, 2015 7:14 pm

@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.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
69
S
18
G
65
Posts: 2,195
Reputation: 41,465

Post » Sat Mar 14, 2015 10:01 pm

@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.
Image
B
32
S
11
G
2
Posts: 563
Reputation: 5,106

Post » Sat Mar 14, 2015 10:34 pm

@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!
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
69
S
18
G
65
Posts: 2,195
Reputation: 41,465

Post » Sat Mar 14, 2015 11:46 pm

@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).
Image
B
32
S
11
G
2
Posts: 563
Reputation: 5,106

Next

Return to Work in Progress Addons

Who is online

Users browsing this forum: jobel and 1 guest