]> git.cameronkatri.com Git - gmtk-gamejam.git/commitdiff
Add movement to limbs
authorCarson Katri <carson.katri@gmail.com>
Sat, 12 Jun 2021 18:20:38 +0000 (14:20 -0400)
committerCarson Katri <carson.katri@gmail.com>
Sat, 12 Jun 2021 18:20:38 +0000 (14:20 -0400)
Assets/Prefabs/Player.prefab
Assets/Scenes/Main.unity
Assets/Scripts/Controllers/Ball.cs
Assets/Scripts/Controllers/GameController.cs
Assets/Scripts/Controllers/Player/PlayerController.cs
Assets/Scripts/Controllers/Player/PlayerSegment.cs

index 2b028587c9724f96a4177a04bbf58859f4aab155..521b4bf375113ad37a5fc7b1c5d3c442b0ab460a 100644 (file)
@@ -1123,9 +1123,13 @@ MonoBehaviour:
   left:
     keyCode: 276
     icon: {fileID: 5020703169596630212}
+    leg: {fileID: 414971659141114100}
+    arm: {fileID: 8549221634172624537}
   right:
     keyCode: 275
     icon: {fileID: 476429766403681147}
+    leg: {fileID: 5886521033835613979}
+    arm: {fileID: 8845918641001187994}
   forceOrigin: {x: 0, y: 0.5, z: 0}
   height: 0
 --- !u!50 &6095859832867562452
@@ -1411,9 +1415,13 @@ MonoBehaviour:
   left:
     keyCode: 97
     icon: {fileID: 5321565721314628342}
+    leg: {fileID: 2835159121523199489}
+    arm: {fileID: 6791963013674012835}
   right:
     keyCode: 100
     icon: {fileID: 7797841368364398355}
+    leg: {fileID: 3531439111263992317}
+    arm: {fileID: 61032117990659215}
   forceOrigin: {x: 0, y: -0.5, z: 0}
   height: 0
 --- !u!50 &6095859833589646292
@@ -1518,6 +1526,8 @@ MonoBehaviour:
   controls:
     grab: 119
     shoot: 273
+  maxLegAngle: 30
+  legSpeed: 10
 --- !u!1 &6791963013674012835
 GameObject:
   m_ObjectHideFlags: 0
index e44b3313bc6d41dff49ed65e7081c8f8251253cb..d003365a0b195309b01d06c48b8232053c4e9f63 100644 (file)
@@ -425,6 +425,10 @@ PrefabInstance:
       propertyPath: game
       value: 
       objectReference: {fileID: 1174357920}
+    - target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
+      propertyPath: legSpeed
+      value: 5
+      objectReference: {fileID: 0}
     - target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
       propertyPath: sensitivity
       value: 2
index b63c9282d1ea13b0cd8356442da247360d9dd653..b09b1be5452d4832f9c0d3186e721e97e8cc0370 100644 (file)
@@ -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);
     }
   }
 }
index 2ae5f215331bc57438f5bd293a4b9c3b460f4842..c326c4ef78540c9fb233826fe60e1ae22448e5fc 100644 (file)
@@ -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()
     {
index e0de738ed835d938b64fac1be443aac6e85fc25c..eca46413b7df5994a12e971dcf5decb935020d83 100644 (file)
@@ -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.
index b4b32677ac00b34663a77caf180e67d4326d82b9..b713442b5205cf4a83e092d8dadf7e27bb6fd0bc 100644 (file)
@@ -22,5 +22,7 @@ namespace Controllers.Player
   {
     public KeyCode keyCode;
     public GameObject icon;
+    public GameObject leg;
+    public GameObject arm;
   }
 }