There is an example in the testbed demonstrating single sided platforms using a very basic case of a square platform. I am trying to take this one step further and apply it to sloping platforms.
Since the character in the game is the shape of a circle and our platforms can be many different shapes I came with the idea of adding an "Angle" parameter to the level editor to calculate which side the character is coming from.
It looks a bit like this inside PreSolve
This actually works very well for the most part apart from the fact the character will "jitter" as it's pushed out from the centre of the platform when it reaches it's "top side". I was curious if people had some ideas on how to solve this particular problem.
(I'll attach a picture of the level editor with the Angle parameter to help visualize the problem)
Since the character in the game is the shape of a circle and our platforms can be many different shapes I came with the idea of adding an "Angle" parameter to the level editor to calculate which side the character is coming from.
It looks a bit like this inside PreSolve
Code:
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
b2Vec2 point1 = worldManifold.points[0];
b2Vec2 point2 = worldManifold.points[1];
float radiansLo = DEGREES_TO_RADIANS(platform->Angle - 180); // left side of platform
float radiansHi = DEGREES_TO_RADIANS(platform->Angle); // right side of platform
float radians = radiansBetweenPoints(actorPos, point1); // radians between player position and point1
if (radians >= radiansLo && -radians <= radiansHi) // are we coming from below the platform?
contact->SetEnabled(false); // yes so turn off collision
contact->GetWorldManifold(&worldManifold);
b2Vec2 point1 = worldManifold.points[0];
b2Vec2 point2 = worldManifold.points[1];
float radiansLo = DEGREES_TO_RADIANS(platform->Angle - 180); // left side of platform
float radiansHi = DEGREES_TO_RADIANS(platform->Angle); // right side of platform
float radians = radiansBetweenPoints(actorPos, point1); // radians between player position and point1
if (radians >= radiansLo && -radians <= radiansHi) // are we coming from below the platform?
contact->SetEnabled(false); // yes so turn off collision
This actually works very well for the most part apart from the fact the character will "jitter" as it's pushed out from the centre of the platform when it reaches it's "top side". I was curious if people had some ideas on how to solve this particular problem.
(I'll attach a picture of the level editor with the Angle parameter to help visualize the problem)