rotated top player

main
Benjamin Kraft 2 years ago
parent 0df62f18f4
commit 15b7271ee1
  1. 5
      Assets/Scripts/Game/AIPlayer.cs
  2. 9
      Assets/Scripts/Game/Player.cs

@ -70,7 +70,8 @@ namespace Game {
// TODO solution for balls outside of border // TODO solution for balls outside of border
// TODO Also must include fact that players have a height, maybe check the incoming angle // TODO Also must include fact that players have a height, maybe check the incoming angle
private bool IsPositionReachableInTime(float futurePosition, float seconds) { // angle: 0 -> perpendicular, from -90 to 90
private bool IsPositionReachableInTime(float futurePosition, float seconds, float angle) {
float requiredDistance = Mathf.Abs(futurePosition - X()) - Width / 2; float requiredDistance = Mathf.Abs(futurePosition - X()) - Width / 2;
if (requiredDistance < 0) if (requiredDistance < 0)
return true; return true;
@ -97,7 +98,7 @@ namespace Game {
// Horizontal line (player line) -> stop simulating // Horizontal line (player line) -> stop simulating
if (Intersect(origin, end, playerLeft, playerRight, out Vector2 point, out Vector2 rs)) { if (Intersect(origin, end, playerLeft, playerRight, out Vector2 point, out Vector2 rs)) {
secondsUsed += secondsLeft * rs.x; secondsUsed += secondsLeft * rs.x;
if (!IsPositionReachableInTime(point.x, secondsUsed)) if (!IsPositionReachableInTime(point.x, secondsUsed, Vector2.Angle(velocity, transform.up)))
impossible = true; impossible = true;
return point.x; return point.x;
} }

@ -38,15 +38,15 @@ namespace Game {
protected void ClampInsideBorders() { protected void ClampInsideBorders() {
if (LeftSide < -Border) if (LeftSide < -Border)
transform.Translate(Vector2.right * (-Border - LeftSide)); transform.Translate(Vector2.right * (-Border - LeftSide), Space.World);
if (RightSide > Border) if (RightSide > Border)
transform.Translate(Vector2.left * (RightSide - Border)); transform.Translate(Vector2.left * (RightSide - Border), Space.World);
} }
protected void TryLinearMove(float h) { protected void TryLinearMove(float h) {
Vector2 trans = new Vector2((goingLeft ? -1 : 0) + (goingRight ? 1 : 0), 0); Vector2 trans = new Vector2((goingLeft ? -1 : 0) + (goingRight ? 1 : 0), 0);
trans *= Speed * h; trans *= Speed * h;
transform.Translate(trans); transform.Translate(trans, Space.World);
ClampInsideBorders(); ClampInsideBorders();
} }
@ -57,6 +57,9 @@ namespace Game {
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
transform.position = new Vector2(0, y); transform.position = new Vector2(0, y);
if (Side == ESide.Top) {
transform.Rotate(transform.forward, 180);
}
} }
} }

Loading…
Cancel
Save