public bool GetPointByLenght(ref Vector3 point, ref Vector3 direction, float len) { int count = curveLenght.Length; for (int i = 1; i < count;) { float curLen = curveLenght[i]; if (len < curLen) { float progress = len / curLen; Vector3 p0, p1, p2, p3; p0 = p1 = p2 = p3 = Vector3.zero; GetCurvePoint(i, ref p0, ref p1, ref p2, ref p3); point = Hermite.GetPoint(p0, p1, p2, p3, progress, tension, bias); return(true); } else { len -= curLen; } ++i; if (i >= count) { i = 1; } } return(false); }
private float CalcCurveLenght(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) { float len = 0; const float lineStep = 1000; Vector3 lineStart = Hermite.GetPoint(p0, p1, p2, p3, 0, tension, bias); for (int i = 1; i <= lineStep; ++i) { Vector3 lineEnd = Hermite.GetPoint(p0, p1, p2, p3, i / (float)lineStep, tension, bias); len += (lineEnd - lineStart).magnitude; lineStart = lineEnd; } return(len); }
public Vector3 GetPoint(float t) { int i; if (t >= 1f) { t = 1f; i = splineControlPoints.Count - 2; } else { t = Mathf.Clamp01(t) * CurveCount; i = (int)t; t -= i; } return(Hermite.GetPoint(t, splineControlPoints[i].Position, splineControlPoints[i].Tangent, splineControlPoints[i + 1].Position, splineControlPoints[i + 1].Tangent)); }
void OnDrawGizmos() { if (points == null) { InitPoints(); } if (points == null) { return; } int count = points.Length; if (count < 4) { return; } Vector3 p0, p1, p2, p3; p0 = p1 = p2 = p3 = Vector3.zero; Gizmos.color = new Color(1, 0, 0, 1); for (int i = 1; i < count; ++i) { GetCurvePoint(i, ref p0, ref p1, ref p2, ref p3); const float lineStep = 100; Vector3 lineStart = Hermite.GetPoint(p0, p1, p2, p3, 0, tension, bias); for (int index = 1; index <= lineStep; ++index) { Vector3 lineEnd = Hermite.GetPoint(p0, p1, p2, p3, index / (float)lineStep, tension, bias); Gizmos.DrawLine(lineStart, lineEnd); lineStart = lineEnd; } } }
void Update() { switch (St) { case State.standbyMove: // 進行率を更新 float befRatio = moveRatio; moveRatio = ((Time.time - actionBeginTime) / StandbyMoveTime); moveRatio = Mathf.Clamp(moveRatio, 0.0f, 1.0f); // 進行率から位置と向きを求める transform.position = Hermite.GetPoint(moveRatio); if (befRatio != moveRatio) { transform.rotation = Quaternion.LookRotation(Hermite.GetPoint(moveRatio) - Hermite.GetPoint(befRatio)); } if (moveRatio >= 1.0f) { St = State.aim; // 待機モーション開始 motion.StartAnimation(HumanMotion.AnimaList.Wait); ThrowStandby(); } break; case State.aim: // ターゲットに向く transform.LookAt(targetPoint); if ((Time.time - actionBeginTime) >= aimTime) { St = State.actionBefore; // 的の移動を終了 Destroy(targetPoint.GetComponent <FollowTarget>()); // 投げモーション開始 motion.StartAnimation(HumanMotion.AnimaList.Throw); } break; case State.actionBefore: // actionAfterへはアニメーションイベントでThrowActionを呼び出して遷移 // if ((Time.time - actionBeginTime) >= actionBeforeStanbdyTime) { // // 投げる // ThrowObject(throwVec); // St = State.actionAfter; // // // 待機モーション開始 // motion.StartAnimation(HumanMotion.AnimaList.Wait); // } break; case State.actionAfter: if ((Time.time - actionBeginTime) >= actionAfterStanbdyTime) { St = State.aim; // 古い的を削除 FadeColor destroyFade = targetPoint.gameObject.AddComponent <FadeColor>(); destroyFade.ColList.Add(new Color(0.0f, 0.0f, 0.0f, 0.0f)); destroyFade.DestroyOnLastFadeEnd = true; destroyFade.LoopFade = false; ThrowStandby(); } break; case State.damage: if ((Time.time - actionBeginTime) >= damageStanTime) { St = State.actionBefore; } break; } }