Kinematic bodies in box2d physics

0 favourites
  • 14 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Heyo,

    In construct 2 we have access to box 2d physics. Within this realm we can either chose to have a body that is dynamic (reacts to collisions) or static (doesn't move). There is a third type of body available in box2d that I need and perhaps you do to: The kinematic body. This is a hybrid body that can have a linear velocity but that is unaffected by forces acting on it. In other words, it can move but cannot be moved by other objects. Ever wanted to have a moving platform using physics but gave up because every time the player jumps on it it gets thrown off course? A kinematic body would work well here, but all that you can have in construct 2 is dynamic or static. Not every object that moves needs to be moved by other objects. Check out the link below for a short sequence of code demonstrating its uses and a short explanation.

    http://www.emanueleferonato.com/2012/05 ... ic-bodies/

    Ashley Is there a way to bring this functionality of box2d into construct ? I know there was limitations in the box2d version optimized for javascript /html5 (you can't disable collisions- Why is this btw?. Having collision masks would be super helpful). Is this perhaps the same with kinematic bodies? Is the code for this body type already in construct, it just doesn't have editor support?

    and while i'm on the topic of box 2d, is it possible to have chain shapes in construct? Wherever there are internal edges, dynamic bodies trip up on them, chains would solve this! or even ghost vertices.

  • Heyo,

    In construct 2 we have access to box 2d physics. Within this realm we can either chose to have a body that is dynamic (reacts to collisions) or static (doesn't move). There is a third type of body available in box2d that I need and perhaps you do to: The kinematic body. This is a hybrid body that can have a linear velocity but that is unaffected by forces acting on it. In other words, it can move but cannot be moved by other objects. Ever wanted to have a moving platform using physics but gave up because every time the player jumps on it it gets thrown off course? A kinematic body would work well here, but all that you can have in construct 2 is dynamic or static. Not every object that moves needs to be moved by other objects. Check out the link below for a short sequence of code demonstrating its uses and a short explanation.

    http://www.emanueleferonato.com/2012/05 ... ic-bodies/

    Ashley Is there a way to bring this functionality of box2d into construct ? I know there was limitations in the box2d version optimized for javascript /html5 (you can't disable collisions- Why is this btw?. Having collision masks would be super helpful). Is this perhaps the same with kinematic bodies? Is the code for this body type already in construct, it just doesn't have editor support?

    if you control a set 'Immovable' object by events to move it, wouldn't that do the exact thing you want?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think it works with events but not with behaviors. A physics platform that moves with the sine behavior won't work for example. Other (dynamic) objects on top of it will look like they "slide" as it moves left and right. The same movement with events will produce different results. Take a look on this topic: https://www.scirra.com/forum/viewtopic.php?f=147&t=104406

  • Aphrodite - It won't work, simply because the only way you can "move" a physics object is by use of a force or impulse. If you change its position to move it then the object will not function as expected in the box2d physics model. If you set a physics object as immovable and then use events to cause it to rotate in place when it strikes another physics object set as dynamic that object will only resolve collision but it won't fly off as though it was hit. The spinning platform can be solved by using a static body and having a dynamic body anchored to it via a revolute joint. The spinner stays in place and imparts a force/impulse on objects it hits. The moving platform is another problem though because it needs to be able to be moved in a way that makes it have force. If you just move it around without using forces it won't behave correctly. If it slams into another object at high speed the object will move just enough to resolve collision.

    eli0s behaviors (such as rotate, or sin) move things via position setting. This breaks the physics system as you are basically teleporting the object around and it has no energy to impart when it collides with another object. As far as I am aware, there is no other way to move a physics object. You can either apply a force or set its position or set the velocity. An immovable object will not respond to any sort of force. The example you posted is interested but as far as I understand it it is a hack around the problem. Kinetic bodies (which already exist in box2d) are meant to solve this problem. Now that I am thinking about it I don't know if I have tried manually setting velocity on a static body, Let me double check that if that works.

  • Ruskul , even without the hack (I am referring to the pin behavior or the solution that marcelokohl suggests) the object behaves as a kinematic, it just isn't very precise. I am not arguing about the need for kinematic objects, I am just saying that there are other ways to achieve similar results.

  • eli0s - I am essentially saying that using pin or setting velocity are the hack arounds. The problem is that using such methods, as you said, are not very precise. More than that, they are not as robust either. they may get the right results for some problems but overall I can't work with that degree of inaccuracy. The video demonstration of box2d kinematics bodies behaves exactly as expected, where the other ways of doing the same thing don't behave the same way. There ends up being a sacrifice of some kind unless you emulate the same stuff going on in box2d via events which would be silly (unless you like using 10,000 events for one object). You are right, there are ways around it, but I figured finding out why its not included in construct is the best place to begin. The code exists in box2d, so why doesn't the feature exist in construct?

  • I agree, though you missed my point. I am telling you that without hack-arounds, you can get results similar to the kinematic bodies. You have to create some extra events (not in the tenths of thousands) and the precision is a bit off, but it can be done. Sure, utilizing everything box2d can offer (I think it can do springs, particles, liquids...) will be super, in the meantime we have to be more creative

    Here, my example with the pin code disabled. It kinda works. It's a start and it uses just 4 events for the platform movement. Other, more advanced users than my self, surely can make it move even with easing in/out, like the Sine behavior does.

  • I think we may have a semantics issue here. That aside, I agree that you can make a work around that will satisfy some needs, but not all needs. Unless the workaround is rewriting box2d through events you will not get the same results as using box2d. This is okay, in some cases. One of the biggest problems with work arounds in contruct is that you aren't actually using or modifying what box2d is doing, you are essentially trying to fix what it does after the fact. I actually need kinetic bodies in full box2d glory. Kind of working isn't an option for what I have in mind for it.

    I looked up some newer features and noted that google has made liquidfun which looks amazing. I think fluid dynamics would be awesome. There is already a jscript version of it, so having it in construct 2 might happen sooner than we think.

  • I understand. There are things you can do so far with workarounds and reinventing the wheel is not intuitive or always possible in some cases.

    Liquidfun came up a few weeks ago and Ashley said that it will cause problems on some platforms and maintaining compatibility could be a problem. I don't think we'll see it any time soon. Here is the topic https://www.scirra.com/forum/box2d-google-liquidfun_t102133?&hilit=liquidfun

  • eli0s - darn, that could be really cool but that is a good point from development standpoint. That is one weakness one size fits all applications.

    I have been going over the code for box2d that comes with contruct2, and kinetic bodies are there. There just isn't editor support. Unless I hear a reason otherwise, I am going to try and get those features that are missing from construct into the editor. The only problem is that it will probably take longer to understand how Ashley has worked it in than it will to make the changes needed.

  • Ruskul I know and understand next to nothing about code, but I think that C2 can be expanded thru the SDK and perhaps Ashley can provide you with the necessary information about those features. Why don't you contact him directly and ask for help..?

  • eli0s , How does one contact him directly? He can't be PM as that is disabled for his account. Usually mentioning his name has brought him to the forum post in my experience, though not this time ):

    Ashley ?

  • Yes the Ashley is the way to lure him out his magnificent layout, from which he is plotting the next C2 release for the sole purpose to sweep us of our feet!!!

    Sorry, I am just too exited from the new lighting system!!!

  • ya, I am pretty excited about that too. I spent a week, looking around and learning how to make it happen and then had to back shelve it for more important considerations/deadlines. I am looking very much forward to it!

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