Top-down moving platform problem

Posts that don't fit into other categories.
soylomass
Posts: 22
Joined: Fri Nov 18, 2016 3:40 pm

Top-down moving platform problem

Postby soylomass » Sun Dec 24, 2017 4:06 pm

Hi, I'm developing a top-down game where player can stand above moving platforms.

I've found solutions for this, either by recording an stand anchor relative to the platform and setting the position of the player to it on every step, or using a PinJoint (tried with RopeJoint but didn't go well).

The problem is I need the player to collide with bodies welded on top of the platform, and:
- In the first case (setPosition) the player just ignores the bodies.
- In the second (PinJoint) the player pushes the welded body, causing the platform to move as well.

Illustration: (brown = platform, green = player, gray = welded bodies)

Image

Is there any solution? Is there any way to make that forces applied to welded bodies don't affect the platform?

Thanks in advance.

PS: One solution would be to use a PinJoint for every body I want to be on top of the platform, so that their interactions don't affect the platform, but I think that would reduce performance (I guess a WeldJoint is more performant than using a PinJoint and setting it's target at every step, isn't it?)

William
Site Admin
Posts: 373
Joined: Sat Feb 06, 2010 10:23 pm

Re: Top-down moving platform problem

Postby William » Tue Dec 26, 2017 10:48 am

I don't think I fully understand the problem, but let me try my best:

soylomass wrote:Is there any solution? Is there any way to make that forces applied to welded bodies don't affect the platform?

So you want collisions with the welded bodies, but you don't want the collisions to affect the platform body? They grey bodies - are they movable with respect to the platform? If not, I'd just make them part of the platform body and make the platform INFINITE mass. So something like:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.java)
  1. Body platform = //
  2. BodyFixture brown = platform.addFixture(Geometry.createSquare(3.0));
  3. BodyFixture grey1 = platform.addFixture(Geometry.createCircle(0.25));
  4. BodyFixture grey2 = platform.addFixture(Geometry.createCircle(0.25));
  5. platform.setMass(MassType.INFINITE);
  6.  
  7. // move the grey one's where you want them
  8. grey1.getShape().translate(-1.0, 1.0);
  9. grey2.getShape().translate(1.0, -1.0);
  10.  
  11. // setup whether they are ignored or not
  12. // you could toggle these if needed
  13. grey1.setSensor(true);
  14. grey2.setSensor(false);

Then the grey bodies will move with the platform without any other construct. You'd need to control the motion of the platform manually, but that may be what you want anyway.

William

soylomass
Posts: 22
Joined: Fri Nov 18, 2016 3:40 pm

Re: Top-down moving platform problem

Postby soylomass » Tue Dec 26, 2017 12:19 pm

That could be a solution, but I forgot to say I need the platform to be dynamic, affected by forces.

For now, I've solved it by making the welded bodies LINEAR_FIXED and setting their linear velocities to the linear velocity of the points they are fixed to (correcting it's position over time). I don't know how performant it will be when there are a lot of bodies though.

William
Site Admin
Posts: 373
Joined: Sat Feb 06, 2010 10:23 pm

Re: Top-down moving platform problem

Postby William » Tue Dec 26, 2017 9:08 pm

soylomass wrote:For now, I've solved it by making the welded bodies LINEAR_FIXED and setting their linear velocities to the linear velocity of the points they are fixed to (correcting it's position over time). I don't know how performant it will be when there are a lot of bodies though.

No problem.

As for performance, I wouldn't worry about it. The only thing I can think of that might impact performance would be that the WeldJoint (and most joints for that matter), perform position correction in the position solver. The position solver iterates until all joints and contacts are within the linear distance tolerance or the maximum number of position iterations has been reached. It can exit early (thereby improving performance) if everything is within that tolerance. Changing the position or velocity could cause the solver to iterate the maximum number every time (default is 10 I think). However, if the manual change in position/velocity is small, then it might have no effect.

William


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests