Kinematic bodies in box2d physics

Discussion and feedback on Construct 2

Post » Tue May 20, 2014 9:06 pm

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.
Last edited by ruskul on Wed May 21, 2014 8:17 pm, edited 2 times in total.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Tue May 20, 2014 10:18 pm

ruskul wrote: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?
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Tue May 20, 2014 11:34 pm

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
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Wed May 21, 2014 1:09 am

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

Post » Wed May 21, 2014 1:36 am

@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.
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Wed May 21, 2014 7:35 pm

@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?
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Wed May 21, 2014 7:51 pm

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.
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Wed May 21, 2014 8:32 pm

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

Post » Wed May 21, 2014 9:35 pm

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
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Thu May 22, 2014 6:06 pm

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

Next

Return to Construct 2 General

Who is online

Users browsing this forum: dierv, zenox98 and 7 guests