Kinematic Bodies

Hello,

I am having some issues with Kinematic objects. I am currently making a platformer game. My main player is a dynamic object (since I need it to rotate), my environment is static. One of the features of the game is a "door" that can be activated with a switch. When the switch is pressed, the door will start moving up, slowly, and after a few seconds, the door will close automatically.

Since my game is tile based, I decided to not make the door a single object, but rather pieces connected as a linked list. When the door opens, all pieces move together, each part stopping when it gets to the "door base", kinda like folding. When the door closes, the first piece will move, after it goes to the next tile, the next piece will move, and so on, until the first piece touches the ground, and all of them will stop moving at once.

Since I need to set force or velocity, a static object is out of the question. I tried using dynamic objects with a very high density, but the player was still able to move it, so my last choice was a kinematic object. It works great with the player, since its dynamic, and it does not collide with the base, since thats static. The main problem is that I would like the collision with the next tile:

For example, a door that opens sideways

1BDDD2

where 1/2 are wall, B is the base, and D is the door part. Initially the door will open towards 1, and the second that each D collides with 1, their velocities will be set to zero. When the door closes, the first D will move, then the second and so on until the first D collides with 2, and all of the door parts will stop.

The main problem is that 1 and 2 are static objects, and as such don't collide with kinematic objects. I could set up some sort of dynamic sensor in 1 and 2, and the second the ContactListener lets me know that the door part collided with it, then I will do the correct behavior.

My question is, is that the only way for me to achieve this behavior? or is there a better way (rather than me having to place sensors all over the place where the doors are).

Here is the link to the current build of my game (its going to be a facebook game). https://apps.facebook.com/_repulsetest/ The orange thing is the door base. This build does not have the door parts yet, but at least will give an idea how it will look.

Thanks in advance!
If you know the position where the blocks should stop moving, and this position is static, can't you just check the position of each kinematic block as it moves and stop moving it if it has already moved far enough?

The game looks great by the way!
irresistible force wrote:
If you know the position where the blocks should stop moving, and this position is static, can't you just check the position of each kinematic block as it moves and stop moving it if it has already moved far enough?


That's the problem. I don't always know where the kinematic object would be as the game is data driven. I am almost done implementing that method I mentioned. I was hoping that there would be a more elegant solution.

irresistible force wrote:
The game looks great by the way!


Thanks! We been working on it (part-time) for a few months now.
I still don't get it... if you knew where to place the D blocks and the 1/2 blocks in the first place then I would assume you'd know how far and in what direction they each need to move to get the the 'open' or 'closed' position.
irresistible force wrote:
I still don't get it... if you knew where to place the D blocks and the 1/2 blocks in the first place then I would assume you'd know how far and in what direction they each need to move to get the the 'open' or 'closed' position.


That's actually a good point. I didn't think of it that way. What I ended up doing is placing a dynamic sensor on top of the base, and at the bottom of the last door part, and let it take care of itself (i.e. once the door hits either sensor in the contact listener, it sets the velocity to zero).

Original thread: https://box2d.org/forum/viewtopic.php?t=7668