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