Itween Parabolic Linear Movement

Source: Internet
Author: User

never had time to write a blog. Today, record The parabolic movement usage of itween.

The main story is one instance:

first set up a Span lang= "en-US" style= "FONT-SIZE:9PT; Font-family:consolas; border:1pt none windowtext; padding:0cm ">plane cube


planewith theMesh Colliderwill cause the resource to become larger, so useCubeinstead of making the scene (the yellow floor isCubeWhite isplane).


Plane here is to follow the role of the mouse so that his mesh collider deleted.

Here's a script that the mouse follows:

1.using unityengine;  2.using System.Collections;    3.4.public class Course:monobehaviour {5.  public Gameobject target;      6.7.    8.9.      void Start () {10.      11.} 12.    13.14.        void Update () {15.        Mouse follows 16. Ray Ray = camera.  Screenpointtoray (input.mouseposition);  Raycasthit hit;        if (Physics.raycast (Ray, out hit)) 19. {. if (Hit.transform.gameObject.tag = = "Tile") 
                 /* Note that the tile here is a cube, which is where you are looking for the mouse to move on the cube. As you can see from the cube attribute map at the top of this article, his tag is tile.*/  .            {                itween.moveupdate (target, New Vector3 (Hit.point.x, 0.1f, Hit.point.z),. 1f);                  <pre name= "code" class= "CSharp" >/* here the target is plane, we are to implement plane follow the mouse, here in the panel to the plane this preset to the target. And the code in the <pre name= "code" class= "CSharp" style= "FONT-SIZE:24PX;" >new Vector3 (Hit.point.x, 0.1f, Hit.point.z),. 1f  This sentence is: hit means that the position of the mouse has XYZ axis position, only the x,z two axis motion, so write y as 0.1f. There's another one at the end. 1f represents the time that plane follows the mouse. The longer the time means that the plane walk the slower, the mouse to the target location plane or to continue to come over * *

}
}
}
}
}
<span style= "FONT-SIZE:9PT; Font-family: Song body; border:1pt none windowtext; padding:0cm; " > Just put this script </span><span lang= "en-US" style= "FONT-SIZE:9PT; Font-family:consolas; border:1pt none windowtext; padding:0cm; " >course</span><span style= "FONT-SIZE:9PT; Font-family: Song body; border:1pt none windowtext; padding:0cm; " > Drag to the camera to run it like:</span>


Mouse follow can be achieved. When you look at a mouse click, a small ball will run to the mouse click position. below is COURSE&NBSP; All contents:

 1.using unityengine;2.using System.Collections;    3.4.public class Course:monobehaviour {5.  public Gameobject target; 6. vector3[] paths = new vector3[3];/* Here is a 3-dimensional array representing the starting and target points of the ball and a point between the starting point and the target point.    */7. Public Gameobject ballperfab;/* in the code explained: here <pre name= "code" class= "CSharp" style= "FONT-SIZE:24PX;" >ballperfab is the course script in the Ballperfab, pay attention to put the sphere inside. This is the ball that is going to be moving. *//Use the This for Initializationvoid Start () {}void Update () {//mouse follow just above said Ray Ray = camera. Screenpointtoray (input.mouseposition); Raycasthit hit; if (Physics.raycast (Ray, out)) {if (Hit.transform.gameObject.tag = = "Tile") {itween.moveupdate (target, new Vector3 (H  It.point.x, 0.1f, Hit.point.z),. 1f);               1.if (Input.getmousebuttondown (0))//Here is a condition where the mouse click executes the following statement 2. {3. Gameobject ball= (Gameobject) Instantiate (Ballperfab, new Vector3 (0, 0, 0), quaternion.identity);                    /instanced Ball 4.        5. Paths[0] = new Vector3 (0, 0, 0);//Start point 6.           PATHS[2] = hit. Point;//endpoint, that is, mouse click 7.                   PATHS[1] = new Vector3 (paths [1].X/2, 1, paths [2].Z/2);/* points between start and end point, note the XZ two axes, one half of the starting point coordinates and half of the end coordinates */8.                Itween.moveto (Ball, Itween.hash ("path", paths));/* In fact, this is the path, a hash table but the official website is the following sentence commented out, just add some other conditional attributes */9. Itween.moveto (Ball, Itween.hash ("path", Paths, "Oregin", True, "Movetopath", True, "time", 1, "Easytype", Itween.eas  Etype.linear));                   10.11.  Destroy (ball, 2);//clone a bunch of small balls to remove, so every two seconds Destroy one.  12.} 13.     14.} 15.  16.} 17.  18.19.}      20.21.       void Ondrawgizmos ()/* This is path's route and its color setting is visible */22.  {Itween.drawline (paths, Color.Blue);  Debug.Log ("1111111111111111111111111111111");   Itween.drawpath (paths, color.red);





Itween Parabolic Linear Movement

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.