var playerHoopDistance = Mathf.Abs(player.root.transform.position.x - game.EnemyHoop.transform.position.x);
if (hoopDistance < 6f && hoopDistance > 2.5f && (Random.Range(0, 100) > 30 || playerHoopDistance > hoopDistance)) // Take the shot when in range. 70% chance he decides to if the player is standing between him and the basket.
{
- game.enemy.Shoot(transform);
+ game.enemy.Shoot(transform, 0f);
}
}
controller.BallDropped();
}
- public void Shoot(Vector3 target)
+ public void Shoot(Vector3 target, float time)
{
transform.right = target - transform.position;
Rigidbody.velocity = Vector2.zero;
- Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * shotForce);
+ Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * (shotForce * ((Mathf.Clamp(time, 0f, 1f) + 1))));
}
}
}
/// Shoot the ball if possible.
/// </summary>
/// <param name="playerTransform"></param>
+ /// <param name="time"></param>
/// <returns>Whether or not the ball was shot</returns>
- public bool Shoot(Transform playerTransform)
+ public bool Shoot(Transform playerTransform, float time)
{
if (controller.state != dribble) return false; // We must be dribbling the ball to shoot it.
controller.BallAnimation.enabled = true;
controller.dribbleSound.Stop();
controller.state = shoot;
controller.ball.Rigidbody.bodyType = RigidbodyType2D.Dynamic;
- controller.ball.Shoot(hoop.transform.position);
+ controller.ball.Shoot(hoop.transform.position, time);
lastShotPosition = playerTransform.position;
return true;
}
public PlayerSegment root => segments[0];
+ private float ShootStartTime;
+
private void Awake()
{
foreach (var segment in segments) {
// Try shooting the ball if pressed.
if (Input.GetKeyDown(controls.shoot))
- game.player.Shoot(segments.Last().transform);
+ ShootStartTime = Time.time;
+
+ if (Input.GetKeyUp(controls.shoot))
+ game.player.Shoot(segments.Last().transform, ShootStartTime - Time.time);
}
[Serializable]