]> git.cameronkatri.com Git - gmtk-gamejam.git/blobdiff - Assets/Scripts/Controllers/Ball.cs
Add non working time shooting
[gmtk-gamejam.git] / Assets / Scripts / Controllers / Ball.cs
index fa9c25197f95350d23df5fc0313d87313238855e..936b857e1b83ed4aca69ede6e99699aa6530d760 100644 (file)
@@ -11,18 +11,20 @@ namespace Controllers
     internal GameController controller;
 
     [SerializeField] private float shotForce;
+
+    public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
+    private Rigidbody2D _rigidbody;
     
     private void OnCollisionEnter2D(Collision2D other)
     {
       controller.BallDropped();
     }
 
-    public void Shoot(Transform playerTransform)
+    public void Shoot(Vector3 target, float time)
     {
-      transform.right = (controller.PlayerHoop.transform.position - transform.position);
-      var rigidbody = GetComponent<Rigidbody2D>();
-      rigidbody.velocity = Vector2.zero;
-      rigidbody.AddForce(transform.right * shotForce);
+      transform.right = target - transform.position;
+      Rigidbody.velocity = Vector2.zero;
+      Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * (shotForce * ((Mathf.Clamp(time, 0f, 1f) + 1))));
     }
   }
 }