The moving ① of Unity3d sequence target point in time cooking rain

Source: Internet
Author: User

Series Catalogue

"Unity3d base" lets the object move ①--based on the Ugui mouse click Movement

"Unity3d base" let the object move ②--ugui mouse click Frame

Time boiled rain Unity3d let the object move ③-ugui dotween&unity native2d Realization

Time to boil the rain Unity3d realize 2D character animation ①ugui&native2d sequence frame animation

Time to boil the rain Unity3d realize 2D character animation ②unity2d animation System & Resource Efficiency

Time boiled rain Unity3d realize 2D character Movement-Summary

The moving ① of Unity3d sequence target point in time cooking rain

Background

On the role of the mouse click to move the summary, feel their experience is a little bursting feeling, can be a small rise of a level, although the theme is relatively small but the basis of animation, and the game itself is based on animation, so it is very meaningful.

In order to study the 2d pathfinding algorithm, A * pathfinding, A * pathfinding is based on the grid, so the movement of the sequence point becomes my research direction. Here, after some effort, there are several directions.

A, Dotween has a sequence animation combination to meet

B, a similar function in ITween but not fully satisfied

C, the realization of their own

This article mainly organized on-line resources to do a tidy, shared out.

Realize

A, dotween this is actually very simple, directly with the function on the line, just feel a little uncomfortable, people are doing a combination of animation, feel overkill feeling, decisively gave up

B, a similar function in ITween but not satisfied

Here why say not satisfied, borrow rain pine Momo pictures, a look will know

Where the red line is the plug-in curve interpolation is worth the result (based on 3 points, the operation is quite complex), and the Yellow Line is the debug display of the 4 points of the line guides, if the direct use of the plug-in to get the running trajectory is not to review my requirements, However, the use of Itween code is relatively simple to see (here plagiarism Momo the original link is: Itween Institute of Learning Notes Move Mobile chapter (a))

Using Unityengine;
Using System.Collections;

public class Path:monobehaviour {

All points in the path pathfinding
Public Transform [] paths;

void Start ()
{
Hashtable args = new Hashtable ();
Set the point of the path
Args. ADD ("path", paths);
The set type is linear and the linear effect is better.
Args. ADD ("Easetype", iTween.EaseType.linear);
Set the speed of pathfinding
Args. ADD ("Speed", 10f);
Whether to go from the original position to the position of the first point in the path first
Args. ADD ("Movetopath", true);
Do you want the model to always be in the direction of the face target, and the corner will automatically rotate the model
If you find that your model is always in the same direction when you're looking for a path, then be sure to open this.
Args. ADD ("Orienttopath", true);

Let the model begin to find the way
Itween.moveto (Gameobject,args);
}

void Ondrawgizmos ()
{
Draw paths and lines in the scene view
Itween.drawline (Paths,color.yellow);

Itween.drawpath (paths,color.red);

}
}

In fact, I am in the study of the time line based on the movement, the analysis of learning Itween source code, in fact, is the event line interpolation animation, there is no advanced principle. In fact, it is possible to extend the itween to achieve this function, if the principle is clear.

C, the realization of their own

This is the highlight of this article, the following is my google for a long time to find a piece of code (written by foreigners, very simple AH)

void Update ()
{
float Step = speed * time.deltatime;
Transform.position = Vector3.movetowards (Transform.position, Targets[index], step);

if (Vector3.distance (Transform.position, Targets[index]) < 0.01f)
{
if (index = = targets. LENGTH-1)
{
index = 0;
}
Else
index++;
}
}
is not a simple heinous, "the crowd to find him 1100 degrees, suddenly look back, the man is in the dim place." "The actual code prototype is so simple, combined with the advantages of the movetowards mentioned above, is it simple?"

Summarize

The function was finally realized, but there were flaws. The next detailed analysis of the supplemental and animated system of this article continues.

The moving ① of Unity3d sequence target point in time cooking rain

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.