private void CreateBolt(LineRenderer line) { //lineObject.material.SetTextureScale("_MainTex", new Vector2(distance * zigZagPerMeter, 1.0f)); //lineObject.numPositions = vertexCount; float totalDistance = _pathComp.TotalDistance; int numPositions = Mathf.CeilToInt(totalDistance * zigZagPerMeter); Vector3[] points = new Vector3[numPositions]; line.positionCount = numPositions; line.material.SetTextureScale("_MainTex", new Vector2(totalDistance * zigZagPerMeter, 1.0f)); // set the ends points[0] = _pathComp.GetPathPoint(0.0f).point; points[numPositions - 1] = _pathComp.GetPathPoint(totalDistance).point; Vector2 previousOffset = Vector2.zero; for (int i = 1; i < numPositions - 1; i++) { Path_Point pathPoint = _pathComp.GetPathPoint(Math_Functions.Value_from_another_Scope(i, 0, numPositions - 1, 0, totalDistance)); Vector2 offset = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f)); offset *= zigZagIntensity; previousOffset = offset; points[i] = pathPoint.point + (pathPoint.right * offset.x) + (pathPoint.up * offset.y); } line.SetPositions(points); }
private void Craft() { //初始化组件Path_camp _path = GetComponent <Path_Comp>(); // struct Path_Point 包含point,forward,up,right; //GetPathPoint() 返回一个Path_Point 依据传入的distance(距离起始点的距离) Path_Point pointA = _path.GetPathPoint(0.0f);//获得路径的起点 Path_Point pointB = pointA; Path_Point pointB2 = pointA; //_segment_length = max_z - min_z; 传入的dist 为距离起点的两两直线段距离 for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length) { //对于dist=0,dist<总长度,dist=dist+分段的距离 pointB = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance)); //确定B点的位置 pointB2 = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length - (float)0.05, 0, _path._path.TotalDistance)); //确定B点的位置 _helpTransform1.rotation = Quaternion.LookRotation(pointA.forward, pointA.up); //游戏对象1的旋转=z轴朝向view,y轴朝向up _helpTransform1.position = transform.TransformPoint(pointA.point); //对象1的位置是A点的位置 _helpTransform2.rotation = Quaternion.LookRotation(pointB.forward, pointB.up); //游戏对象2的旋转=z轴朝向view,y轴朝向up _helpTransform2.position = transform.TransformPoint(pointB.point); //对象2的位置是B点的位置 Add_Segment(); //添加分段 pointA = pointB2; //A->B } }
void LateUpdate() { if (_particle_array == null) { Start(); _path_comp.Update_Path(); } else if (isPathUpdating) { _path_comp.Update_Path(); } _numParticles = _particle_system.GetParticles(_particle_array); if (_numParticles > 0) { for (int i = 0; i < _numParticles; i++) { ParticleSystem.Particle obj = _particle_array[i]; // This made it based on the particle lifetime // float normalizedLifetime = (1.0f - obj.remainingLifetime / obj.startLifetime); // // if(hasRandomStartingPoints){ // normalizedLifetime += Get_Value_From_Random_Seed_0t1(obj.randomSeed, 100.0f); // normalizedLifetime = normalizedLifetime % 1.0f; // } // // Path_Point axis = _path_comp.GetPathPoint(_path_comp.TotalDistance * normalizedLifetime); // This made it based on the paritcle speed float dist = (obj.startLifetime - obj.remainingLifetime) * obj.velocity.magnitude; if (hasRandomStartingPoints) { dist += Get_Value_From_Random_Seed_0t1(obj.randomSeed, 100.0f) * _path_comp.TotalDistance; } dist = dist % _path_comp.TotalDistance; Path_Point axis = _path_comp.GetPathPoint(dist); Vector2 offset = Vector2.zero; if (pathWidth > 0) { offset = Math_Functions.AngleToVector2D(obj.randomSeed % 360.0f); offset *= Get_Value_From_Random_Seed_0t1(obj.randomSeed, 150.0f) * pathWidth; } _particle_array[i].position = axis.point + (axis.right * offset.x) + (axis.up * offset.y); } _particle_system.SetParticles(_particle_array, _numParticles); } }
public Vector3 GetRightTangent(float dist, Path_Comp path) { //kinda false tangent gonna fix that soon //tangentdist should be 0.05 or smth Vector3 tangent = Vector3.zero; tangent = path.GetPathPoint(dist).right; return(tangent); }
public Vector3 GetTangent(float dist, Path_Comp path) { //kinda false tangent gonna fix that soon //tangentdist should be 0.05 or smth Vector3 tangent = Vector3.zero; tangent = path.GetPathPoint(dist).forward; //StartCoroutine(Math_Functions.CatmullRomThread()); return(tangent); }
private void Craft() { _path = GetComponent <Path_Comp>(); Path_Point pointA = _path.GetPathPoint(0.0f); Path_Point pointB = pointA; for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length) { pointB = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance)); _helpTransform1.rotation = Quaternion.LookRotation(pointA.forward, pointA.up); _helpTransform1.position = transform.TransformPoint(pointA.point); _helpTransform2.rotation = Quaternion.LookRotation(pointB.forward, pointB.up); _helpTransform2.position = transform.TransformPoint(pointB.point); Add_Segment(); pointA = pointB; } }
public Vector3[] GetTrackPoints() { ScanSourceMesh(); _path = GetComponent <Path_Comp>(); Path_Point pointA = _path.GetPathPoint(0.0f); Path_Point pointB = pointA; int totalTrackPoints = (int)(_path._path.TotalDistance / _segment_length) + 1; trackPoints = new Vector3[totalTrackPoints]; int count = 0; for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length) { pointB = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance)); trackPoints[count] = pointA.point; count++; pointA = pointB; } return(trackPoints); }
void LateUpdate() { if (_particle_array == null) { Start(); _path_comp.Update_Path(); } else if (isPathUpdating) { _path_comp.Update_Path(); } _numParticles = _particle_system.GetParticles(_particle_array); if (_numParticles > 0) { for (int i = 0; i < _numParticles; i++) { ParticleSystem.Particle obj = _particle_array[i]; Path_Point axis = _path_comp.GetPathPoint(_path_comp.TotalDistance * (1.0f - obj.remainingLifetime / obj.startLifetime)); Vector2 offset = Math_Functions.AngleToVector2D(obj.randomSeed % 360.0f); offset *= (((float)obj.randomSeed % 100.0f) / 100.0f) * pathWidth; _particle_array[i].position = axis.point + (axis.right * offset.x) + (axis.up * offset.y); _particle_array[i].velocity = axis.forward * _particle_array[i].velocity.magnitude; } _particle_system.SetParticles(_particle_array, _numParticles); } }
void LateUpdate() { #if UNITY_EDITOR if (!Application.isPlaying) { _editorTimeDelta = EditorApplication.timeSinceStartup - _editorTimetracker; _editorTimetracker = EditorApplication.timeSinceStartup; } #endif if (transform.childCount <= 1) { return; } // emision if (_emissionRateTracker <= 0.0f) { _emissionRateTracker += 1.0f / emissionRate; RenewOneDeadParticle(); } _emissionRateTracker -= (Application.isPlaying ? Time.deltaTime : (float)_editorTimeDelta); // age them foreach (PathParticleTracker tracker in _particle_trackerArray) { if (tracker.particle.remainingLifetime > 0.0f) { tracker.particle.remainingLifetime = Mathf.Max(tracker.particle.remainingLifetime - (Application.isPlaying ? Time.deltaTime : (float)_editorTimeDelta), 0.0f); } } float normLifetime = 0.0f; Path_Point Rpoint; // move them foreach (PathParticleTracker tracker in _particle_trackerArray) { if (tracker.particle.remainingLifetime > 0.0f) { normLifetime = tracker.particle.remainingLifetime / tracker.particle.startLifetime; normLifetime = 1.0f - normLifetime; Rpoint = _path_comp.GetPathPoint(normLifetime * _path_comp.TotalDistance); // rotate around Rpoint.direction Rpoint.point += (pathWidth * tracker.distance) * Math_Functions.Rotate_Vector(Rpoint.up, Rpoint.forward, tracker.rotation); tracker.particle.position = Rpoint.point; tracker.particle.velocity = Rpoint.forward; } } _particle_count = 0; // set the given array foreach (PathParticleTracker tracker in _particle_trackerArray) { if (tracker.particle.remainingLifetime > 0.0f) // it's alive { _particle_array[_particle_count] = tracker.particle; _particle_count++; } } _particle_system.SetParticles(_particle_array, _particle_count); }