Platformer with platforms you can pass throught from below

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
kelthar
Posts: 13
Joined: Thu Nov 20, 2014 10:20 pm

Platformer with platforms you can pass throught from below

Post by kelthar »

So, the title spills most of the beans. I have a scenario where I would like to be able to jump through entities without collisions, but then settle on top of them. Do I need to make a hack for this? You can only move across two axis in the game. x and y.

One idea I had is to change the entities position on the z axis while the entity is moving upwards. And then move it back into the plane of collisions. This is a hack and I think it'll have repercussions later.

Could I be using rules for this in any way? Does anyone have any suggestions how to solve this in an elegant or hacky way?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Platformer with platforms you can pass throught from bel

Post by Norbo »

One sided meshes could work. Just use a StaticMesh (or other mesh types) with a Clockwise or Counterclockwise sidedness. Objects will pass through one side and collide with the other. There is small quirk, though- once an entity is about halfway through the surface, a one sided triangle will start applying its own force to bring it all the way through since it views it as deeply interpenetrating. This could be tuned with the CollisionResponseSettings penetration recovery variables, but tuning might not actually be necessary.

For non-triangles, it's possible to change the collision rule of a pair within an immediate event handler (the collision events with present-tense names). For example, in a CreatingContact event, the collision rule of the pair could be changed to NoSolver if the contact's collision normal is facing the wrong way. Getting this robust could take some effort since a lot of contacts with divergent normals are going to be generated as one shape passes through the interior of the other shape.
kelthar
Posts: 13
Joined: Thu Nov 20, 2014 10:20 pm

Re: Platformer with platforms you can pass throught from bel

Post by kelthar »

So, for anyone reading this later and wondering about how I ended up solving it:
What I ended up doing was adding a rule with no collisions between the platform and the player, as long as the player was beneath the platform. Once the player got above the platform I removed the rule. This worked out well. If the player ever drops below the platform, the rule is re-applied. It works, but it might not be elegant.

The StaticMesh-approach didn't work. The player collided with the mesh from both sides. It was probably due to some mistake of mine, but it wasn't apparent from my shallow analysis.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Platformer with platforms you can pass throught from bel

Post by Norbo »

The StaticMesh-approach didn't work. The player collided with the mesh from both sides. It was probably due to some mistake of mine, but it wasn't apparent from my shallow analysis.
For future reference, if the StaticMesh's Sidedness property was set to Clockwise or Counterclockwise and it was still colliding on both sides, it is likely that the mesh contained duplicate triangles that faced both directions.
Post Reply