]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/Controllers/Player/PlayerSegment.cs
4d0fb4f44a66ce541a628be4441015c768ff0cc8
[gmtk-gamejam.git] / Assets / Scripts / Controllers / Player / PlayerSegment.cs
1 using System;
2 using UnityEngine;
3
4 namespace Controllers.Player
5 {
6 [RequireComponent(typeof(Rigidbody2D))]
7 public class PlayerSegment : MonoBehaviour
8 {
9 internal float sensitivity;
10 internal float verticalSensitivity;
11
12 internal bool moveleft;
13 internal bool moveright;
14
15 [SerializeField] public Control left;
16 [SerializeField] public Control right;
17
18 [SerializeField] public Vector3 forceOrigin;
19
20 [SerializeField] public float height;
21 [SerializeField] public bool isRoot;
22 [SerializeField] public bool isTop;
23
24 public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
25 private Rigidbody2D _rigidbody;
26
27 private void FixedUpdate()
28 {
29 if (moveleft)
30 {
31 Rigidbody.AddForceAtPosition(
32 Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
33 transform.position + (height * forceOrigin));
34 }
35 if (moveright)
36 {
37 Rigidbody.AddForceAtPosition(
38 Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
39 transform.position + (height * forceOrigin));
40 }
41 }
42 }
43
44 [Serializable]
45 public struct Control
46 {
47 public KeyCode keyCode;
48 public GameObject icon;
49 public GameObject leg;
50 public GameObject arm;
51 }
52 }