Skip to content

Commit

Permalink
Fix player being moved when hitting solid ceiling
Browse files Browse the repository at this point in the history
Note that variable height jumps exist in the readme controls section
Remove the 1 tile gap from level 3
  • Loading branch information
nfaltermeier committed Apr 6, 2021
1 parent 9b70e4c commit 089f397
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions Components/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,23 @@ public bool OnTouchWall(Fixture sender, Fixture wall, Contact contact)
Vector2 offset = points[0] - points[1];
if (offset.LengthSquared() < 5)
{
Attached.Screen.ScreenManager.
AddPostPhysicsStepAction(() => sender.Body.Position += offset * (reversed ? -1 : 1));
ret = false;
Vector2 raySource = points[reversed ? 1 : 0] + 2 * offset * (reversed ? -1 : 1);
bool hit = false;
MainGame.Instance.World.RayCast(
(Fixture fixture, Vector2 point, Vector2 normal, float fraction) => {
hit = fixture != null;
return fraction;
},
raySource, raySource + new Vector2(0, 0.1f)
);
// If there is open space above where we are going to move the player
// prevents the player from glitching out when touching a ceiling with no gaps
if (!hit)
{
Attached.Screen.ScreenManager.
AddPostPhysicsStepAction(() => sender.Body.Position += offset * (reversed ? -1 : 1));
ret = false;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Content/Levels/3.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,
Expand Down
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Swing. A platforming game. Navigate your blue square to the green square.

## Controls ##
* Movement - WASD
* Jump - Space
* Jump - Space (Longer press means higher jump)
* Interact with menu - Mouse
* Pause - Escape

Expand Down

0 comments on commit 089f397

Please sign in to comment.