Skip to content

Commit

Permalink
Quick bugfix
Browse files Browse the repository at this point in the history
Portal collisions failed to detect at high altitudes when using the
position vector to check for them. Switched to using the step
algorithm's impact point instead.
  • Loading branch information
brianide committed Jun 21, 2020
1 parent 407c199 commit e2c75af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions PortalPutt/PortalPuttPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public void OnCollision(PhysicsProperties properties, ref Vector2 position, ref

private bool TryPortal(ref Vector2 position, ref Vector2 velocity, ref BallCollisionEvent collision)
{
var ent = collision.Entity;

foreach (var (pin, pout) in Util.GetPortalPairs())
{
PortalHelper.GetPortalEdges(pin.Center, pin.ai[0], out Vector2 start, out Vector2 end);
if (Collision.CheckAABBvLineCollision(position, collision.Entity.Size, start, end))
if (Collision.CheckAABBvLineCollision(collision.ImpactPoint - ent.Size / 2, ent.Size, start, end))
{
var ent = collision.Entity;

// The velocity vector has already been reflected from the collision we're responding to, so
// we reflect it back. We then rotate the velocity vector by the rotation of the exit portal less the
// rotation of the entry portal. The vector is backwards at that point, so we negate it.
Expand All @@ -119,7 +119,7 @@ private bool TryPortal(ref Vector2 position, ref Vector2 velocity, ref BallColli
// and translate onto the exit portal.
var portalRelative = (position - pin.Center).RotatedBy(-pin.ai[0]);
portalRelative.X *= -1;
portalRelative.Y = Math.Max(portalRelative.Y, ent.Size.Y * 1.1f);
portalRelative.Y = Math.Max(portalRelative.Y, ent.Size.Y * 0.6f);
position = portalRelative.RotatedBy(pout.ai[0]) + pout.Center;

return true;
Expand Down
4 changes: 2 additions & 2 deletions PortalPutt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]

0 comments on commit e2c75af

Please sign in to comment.