<span id="Label3"></p><p><p><br></p></p><p style="text-align:center"><p style="text-align:center"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><strong>this series of articles by Csdn</strong></span> <span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(255,102,102); font-size:18px"><strong>a day of Moe</strong></span> <span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><strong>produced, without the permission of the blogger may not be Reproduced. </strong></span><br></p></p><p style="text-align:center"><p style="text-align:center"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><strong><br></strong></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><strong></strong> particles in u3d are two-dimensional images rendered in three-dimensional space, usually a particle system consisting of a particle emitter, an animator, and a renderer. We can control each particle on the particle system with a script, and then we'll explain how to make particles in the particle emitter move along a specific path.</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><strong></strong> First of all, to create a particle emitter, we intend to let the resulting particles move in the direction of the following (P1--->p2--->p3--->p4--->p5), that is the Idea:</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"></span></p></p><p style="text-align:left"><p style="text-align:left">let <span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px">'s say that if we use an array to record the position of each particle, so that they follow straight lines to move, then the particles will be arranged in a straight line, which will result in this kind of motion:</span> <span style="color:rgb(102,102,102); font-family:‘Microsoft YaHei‘; line-height:26px; text-align:center; font-size:18px"> </span></p></p> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"></span></p> <p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><br></span></p> </blockquote> </blockquote><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px">This effect is not what I want, I want the particles to move like this, they are in the same direction, but not in a line, like this:</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><br></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px">consider, for this purpose, the need to create an array of positions (such as P1 to P5 postion), An array that represents the direction, then each frame to determine the position of the particle, depending on the position of the current particle to determine its direction of movement, when the particle reaches any point, if it is still in the life cycle, Let it move to the next Point.</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px">OK, The idea is roughly so, open u3d start to achieve effect ~ ~ ~</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px">first, we need to right-click on the hierarchy panel to create a particle system, which will automatically generate a transmitter, and call particle shader to render the resulting particles by default.</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="text-align:center; font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px">Since the newly created particle system will have shape automatically calling the cone type, we need to change it to box so that the particles will move along a straight line:</span></p></p> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px "> <blockquote style=" margin:0 0 0 40px; border:none; padding:0px "> <blockquote style=" margin:0 0 0 40px; border:none; padding:0px "> <blockquote style=" margin:0 0 0 40px; border:none; padding:0px "> <blockquote style=" margin:0 0 0 40px; border:none; padding:0px "> <blockquote style=" margin:0 0 0 40px; border:none; padding:0px "> <p style=" text-align:left "> <sp an style="text-align:center; Font-family: ' Microsoft Yahei '; line-height:26px; Color:rgb (102,102,102); font-size:18px "> </sp></p> <p style=" text-align:left "><span style=" color:rgb (102,102,102); font-family: ' Microsoft Yahei '; line-height:26px; text-align:center; font-size:18px "> <br> </span> </p> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote><p style="text-align:left"><p style="text-align:left"><span style="color:rgb(102,102,102); font-family:‘Microsoft YaHei‘; font-size:18px; line-height:26px; text-align:center">Then create a new script testparticlemovement on the newly created particle system, as shown in the following code:</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"></span></p></p><pre name="code" class="csharp">Using unityengine;using system.collections;using System.collections.generic;public class Testparticlemovement: Monobehaviour{public list<vector3> nodes; Public vector3[] directions; Private Particlesystem particles;void Start () {getcomponent<particlesystem> (). startlifetime = Nodes. Count; If (nodes. Count = = 0) Debug.logerror ("please Add at least 1 node"); Auto-generate direction directions = new Vector3[nodes. Count]; for (int i = 0; i < Nodes. Count; I++) directions[i] = (nodes[i]-((i-1 >= 0)? nodes[i-1]: transform.position));} void Update () {particles = getcomponent<particlesystem> (); particlesystem.particle[] particlelist = new particlesystem.particle[particles.particlecount]; int partcount = Particles. Getparticles (particlelist); for (int i = 0; i < partcount; i++) {//calculate particle current life float timealive = Particlelist[i].startlifetime -particlelist[i].lifetime; Float dist = GetaddeDmagnitude ((int) timealive); int count = 0; Determine the location information while (dist > Getaddedmagnitude (count)) {count++; Particlelist[i].velocity = directions[count]; }} Particles. Setparticles (particlelist, partcount);} Private float getaddedmagnitude (int count) {float addedmagnitude = 0; for (int i = 0; i < count; i++) {addedmagnitude + = directions[i].magnitude; } return addedmagnitude; }}</pre><br>This allows the particle to move correctly along the set Point.<p><p></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><br></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><br></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><br></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-family:‘Microsoft YaHei‘; line-height:26px; color:rgb(102,102,102); font-size:18px"><br></span></p></p><p><p>"u3d" particles move along a specific path</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service