4 namespace Controllers.Player
6 [RequireComponent(typeof(Rigidbody2D))]
7 public class PlayerSegment : MonoBehaviour
9 internal float sensitivity;
10 internal float verticalSensitivity;
12 internal bool moveleft;
13 internal bool moveright;
16 [SerializeField] public Control left;
17 [SerializeField] public Control right;
20 [SerializeField] public Vector3 forceOrigin;
21 [SerializeField] public float height;
22 [SerializeField] public bool isRoot;
23 [SerializeField] public bool isTop;
25 [Header("References")]
26 [SerializeField] private GameController game;
27 [SerializeField] private bool callFoulOnContact;
28 [SerializeField] public Transform flipper;
30 public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
31 private Rigidbody2D _rigidbody;
33 private void FixedUpdate()
37 Rigidbody.AddForceAtPosition(
38 Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
39 transform.position + (height * forceOrigin));
43 Rigidbody.AddForceAtPosition(
44 Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
45 transform.position + (height * forceOrigin));
49 private void OnCollisionEnter2D(Collision2D other)
51 if (!callFoulOnContact) return;
53 Debug.Log(other.gameObject.CompareTag("Ground"));
54 Debug.Log(game.player.HasBall);
56 if (game.player.HasBall && other.gameObject.CompareTag("Ground"))
57 game.player.Foul("LOOSE BALL FOUL");
64 public KeyCode keyCode;
65 public GameObject icon;
66 public GameObject leg;
67 public GameObject arm;