aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorCarson Katri <carson.katri@gmail.com>2021-06-12 14:20:38 -0400
committerCarson Katri <carson.katri@gmail.com>2021-06-12 14:20:38 -0400
commit175345523527fca2e2878ccea1e1be391c778986 (patch)
tree62312d01c45b70e848aa42d47ba729ed5f5c1d9a /Assets/Scripts
parentfd0078b03f3cee926ad77532ec57b25bf5d02240 (diff)
downloadgmtk-gamejam-175345523527fca2e2878ccea1e1be391c778986.tar.gz
gmtk-gamejam-175345523527fca2e2878ccea1e1be391c778986.tar.zst
gmtk-gamejam-175345523527fca2e2878ccea1e1be391c778986.zip
Add movement to limbs
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Controllers/Ball.cs2
-rw-r--r--Assets/Scripts/Controllers/GameController.cs2
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerController.cs41
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs2
4 files changed, 43 insertions, 4 deletions
diff --git a/Assets/Scripts/Controllers/Ball.cs b/Assets/Scripts/Controllers/Ball.cs
index b63c928..b09b1be 100644
--- a/Assets/Scripts/Controllers/Ball.cs
+++ b/Assets/Scripts/Controllers/Ball.cs
@@ -18,7 +18,7 @@ namespace Controllers
public void Shoot(Transform playerTransform)
{
- GetComponent<Rigidbody2D>().AddForce((Vector2)(playerTransform.forward + playerTransform.up) * shotForce);
+ GetComponent<Rigidbody2D>().AddForce((Vector2)(playerTransform.right + playerTransform.up) * shotForce);
}
}
}
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index 2ae5f21..c326c4e 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -16,7 +16,7 @@ namespace Controllers
/// <summary>
/// The single ball for the game.
/// </summary>
- [SerializeField] private Ball ball;
+ [SerializeField] public Ball ball;
private void Awake()
{
diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs b/Assets/Scripts/Controllers/Player/PlayerController.cs
index e0de738..eca4641 100644
--- a/Assets/Scripts/Controllers/Player/PlayerController.cs
+++ b/Assets/Scripts/Controllers/Player/PlayerController.cs
@@ -14,6 +14,9 @@ namespace Controllers.Player
[SerializeField] private GameController game;
[SerializeField] private Controls controls;
+
+ [SerializeField] private float maxLegAngle;
+ [SerializeField] private float legSpeed;
private void Update()
{
@@ -35,12 +38,46 @@ namespace Controllers.Player
// Add forces
if (Input.GetKey(segment.left.keyCode))
- segment.Rigidbody.AddForceAtPosition(Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)), segment.transform.position + (segment.height * segment.forceOrigin));
+ {
+ segment.Rigidbody.AddForceAtPosition(
+ Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) +
+ Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
+ segment.transform.position + (segment.height * segment.forceOrigin));
+ }
+
if (Input.GetKey(segment.right.keyCode))
- segment.Rigidbody.AddForceAtPosition(Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)), segment.transform.position + (segment.height * segment.forceOrigin));
+ {
+ segment.Rigidbody.AddForceAtPosition(
+ Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) +
+ Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
+ segment.transform.position + (segment.height * segment.forceOrigin));
+ }
+
+ // Rotate the legs if we move.
+ if (isRoot)
+ {
+ if (Input.GetKey(segment.left.keyCode) || Input.GetKey(segment.right.keyCode))
+ {
+ segment.left.leg.transform.localRotation =
+ Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * legSpeed));
+ segment.right.leg.transform.localRotation =
+ Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * -legSpeed));
+ }
+ else
+ {
+ segment.left.leg.transform.localRotation = Quaternion.Slerp(segment.left.leg.transform.localRotation, Quaternion.identity, Time.deltaTime * legSpeed);
+ segment.right.leg.transform.localRotation = Quaternion.Slerp(segment.right.leg.transform.localRotation, Quaternion.identity, Time.deltaTime * legSpeed);
+ }
+ }
if (isTop)
+ {
game.player.Move(segment.transform.position);
+
+ // Point the arms at the ball.
+ segment.left.arm.transform.up = -(game.ball.transform.position - segment.left.arm.transform.position);
+ segment.right.arm.transform.up = -(game.ball.transform.position - segment.right.arm.transform.position);
+ }
}
// Try grabbing the ball if pressed.
diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
index b4b3267..b713442 100644
--- a/Assets/Scripts/Controllers/Player/PlayerSegment.cs
+++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
@@ -22,5 +22,7 @@ namespace Controllers.Player
{
public KeyCode keyCode;
public GameObject icon;
+ public GameObject leg;
+ public GameObject arm;
}
}