速度取得修正
This commit is contained in:
parent
1033e6eec6
commit
25aeecbb32
|
|
@ -5,15 +5,15 @@ public class Pan : MonoBehaviour
|
|||
{
|
||||
[SerializeField] private PanController controller;
|
||||
[SerializeField] private float thrust;
|
||||
private static readonly float deadZone = 0.1f;
|
||||
[SerializeField] private float deadZone = 0.1f;
|
||||
|
||||
private void OnTriggerStay2D(Collider2D other)
|
||||
{
|
||||
// 移動量が少ないときは動かない
|
||||
if (controller.Delta.magnitude < deadZone)
|
||||
if (controller.Velocity.magnitude < deadZone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
other.attachedRigidbody.AddForce(controller.Delta * thrust, ForceMode2D.Impulse);
|
||||
other.attachedRigidbody.AddForce(controller.Velocity * thrust, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,8 +15,8 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
|
|||
private Vector3 prevPos;
|
||||
private Vector3 offset;
|
||||
|
||||
private Vector2 delta;
|
||||
public Vector2 Delta => delta;
|
||||
private Vector2 velocity;
|
||||
public Vector2 Velocity => velocity;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
|
|||
|
||||
private void OnDisable()
|
||||
{
|
||||
delta = Vector2.zero;
|
||||
velocity = Vector2.zero;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
@ -35,11 +35,11 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
|
|||
// OnDragが更新されていないフレームでは0にする
|
||||
if (target.position == prevPos)
|
||||
{
|
||||
delta = Vector2.zero;
|
||||
velocity = Vector2.zero;
|
||||
}
|
||||
prevPos = target.position;
|
||||
#if UNITY_EDITOR
|
||||
deltaString = $"delta: {delta.normalized} {delta.magnitude:F3}";
|
||||
deltaString = $"delta: {velocity.normalized} {velocity.magnitude:F3}";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
|
|||
var pos = currentPoint + offset;
|
||||
// 移動範囲を制限
|
||||
pos = targetBorder.bounds.ClosestPoint(pos);
|
||||
delta = pos - targetPos;
|
||||
velocity = (pos - targetPos) / Time.deltaTime;
|
||||
target.position = pos;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class ThermalControl : MonoBehaviour
|
|||
{
|
||||
return;
|
||||
}
|
||||
panSpeed = panController.Delta.magnitude * panFactor;
|
||||
panSpeed = panController.Velocity.magnitude * panFactor;
|
||||
if (panSpeed > deadZone)
|
||||
{
|
||||
temperatureSpeed = Mathf.Lerp(temperatureSpeed, -Mathf.Min(panSpeed, maxDecreaseSpeed), Time.deltaTime / decreaseDuration);
|
||||
|
|
|
|||
Loading…
Reference in New Issue