From 72c0636d460dbff953f14abdee1fd2e6cb6213c0 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sat, 12 Jun 2021 14:59:41 -0400 Subject: Physics in FixedUpdate --- .../Scripts/Controllers/Player/PlayerController.cs | 33 +++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'Assets/Scripts/Controllers/Player/PlayerController.cs') diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs b/Assets/Scripts/Controllers/Player/PlayerController.cs index eca4641..3674d92 100644 --- a/Assets/Scripts/Controllers/Player/PlayerController.cs +++ b/Assets/Scripts/Controllers/Player/PlayerController.cs @@ -17,15 +17,21 @@ namespace Controllers.Player [SerializeField] private float maxLegAngle; [SerializeField] private float legSpeed; - + + private void Awake() + { + foreach (var segment in segments) { + segment.sensitivity = sensitivity; + segment.verticalSensitivity = verticalSensitivity; + } + } + private void Update() { // Loop over each body segment and control it. for (var i = 0; i < segments.Length; i++) { var segment = segments[i]; - var isRoot = i == 0; - var isTop = i == segments.Length - 1; // Update icons foreach (var control in new[] {segment.left, segment.right}) @@ -37,24 +43,11 @@ 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)); - } - - 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.moveleft = Input.GetKey(segment.left.keyCode); + segment.moveright = Input.GetKey(segment.right.keyCode); // Rotate the legs if we move. - if (isRoot) + if (segment.isRoot) { if (Input.GetKey(segment.left.keyCode) || Input.GetKey(segment.right.keyCode)) { @@ -70,7 +63,7 @@ namespace Controllers.Player } } - if (isTop) + if (segment.isTop) { game.player.Move(segment.transform.position); -- cgit v1.2.3-56-ge451