リファクタ

This commit is contained in:
kimura 2021-07-07 16:32:58 +09:00
parent 77f85b3a6a
commit fda7226d6c
2 changed files with 9 additions and 8 deletions

View File

@ -5,14 +5,15 @@ public class Pan : MonoBehaviour
{
[SerializeField] private PanController controller;
[SerializeField] private float thrust;
private static readonly float deadZone = 0.1f;
private void OnTriggerStay2D(Collider2D other)
{
// Debug.Log(controller.Direction);
// 移動量が少ないときは動かない
// if (controller.Delta.magnitude >= 1f) Debug.Log(controller.Delta.magnitude);
var direct = 1f;
direct = controller.Delta.magnitude < 0.1f ? 0 : 1;
other.attachedRigidbody.AddForce(controller.Delta * thrust * direct, ForceMode2D.Impulse);
if (controller.Delta.magnitude < deadZone)
{
return;
}
other.attachedRigidbody.AddForce(controller.Delta * thrust, ForceMode2D.Impulse);
}
}

View File

@ -34,6 +34,9 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
delta = Vector2.zero;
}
prevPos = target.position;
#if UNITY_EDITOR
deltaString = $"delta: {delta.normalized} {delta.magnitude:F3}";
#endif
}
@ -45,9 +48,6 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
// 移動範囲を制限
pos = targetBorder.bounds.ClosestPoint(pos);
delta = pos - targetPos;
#if UNITY_EDITOR
deltaString = $"delta: {delta.normalized} {delta.magnitude:F3}";
#endif
target.position = pos;
}