void Update() { if (splineIterator == null) { Start(); //To avoid problems when we are in editmode } else { float timeToUse = GetComponent <ParticleSystem>().duration; if (customTime > 0) //Use custom time? { timeToUse = customTime; } splineIterator.SetOffsetPercent(myParticleSystem.time / timeToUse); //Get the position Vector3 offsetVector = myTransform.right * offset.x + myTransform.up * offset.y + myTransform.forward * offset.z; myTransform.position = splineTansform.TransformPoint(splineIterator.GetPosition()) + offsetVector; //Set the position if (orientToPath) //Change rotation is needed { myTransform.rotation = Quaternion.LookRotation(splineIterator.GetTangent()); } } }
/// <summary> /// Calculates the point each animation curve point. /// </summary> private void CalculatePoint(float _point, int _loopNumber, BaseSpline.SplineIterator _iterator, SplineParticles _target, float _offset) { _iterator.SetOffsetPercent(_point); //Calc modifiers float lifeTimeModifier = _target.GetComponent <ParticleSystem>().startLifetime; float loopsModifier = _target.loopNumber; Vector3 currentPosition = _target.transform.TransformPoint(_iterator.GetPosition()); Vector3 tangentAtPoint = (_iterator.GetTangent().normalized); Vector3 velocityAtPoint = Vector3.zero; if (_point == 0 && _target.Spline.WrapMode == BaseSpline.SplineWrapMode.Loop) { _iterator.SetOffsetPercent(1 - _target.pathQuality); previousPoint = _target.transform.TransformPoint(_iterator.GetPosition()); } else if (_point == 0 && _target.Spline.WrapMode != BaseSpline.SplineWrapMode.Loop) { _iterator.SetOffsetPercent(_point + _target.pathQuality); previousPoint = _target.transform.TransformPoint(_iterator.GetPosition()); } velocityAtPoint = (currentPosition - previousPoint).magnitude * tangentAtPoint; previousPoint = currentPosition; velocityAtPoint *= loopsModifier * (1 / _target.pathQuality) / lifeTimeModifier; _target.velocityCurveX.AddKey(_point / _loopNumber + _offset, velocityAtPoint.x); _target.velocityCurveY.AddKey(_point / _loopNumber + _offset, velocityAtPoint.y); _target.velocityCurveZ.AddKey(_point / _loopNumber + _offset, velocityAtPoint.z); }