- Change namespace (
PathGenerator
>CurvedPathGenerator
) - Edit asset hierarchy
- Minor bug fixes
๐บ ์ ๋ํฐ ๊ณก์ ๊ฒฝ๋ก ์์ฑ๊ธฐ V 2.0
์๋์ ํ๊ตญ์ด ๋ฒ์ญ์ด ์์ต๋๋ค. (There is an Korean translation at the bottom.)
Imagine that you make car running along curved road in Unity Scene.
You can make this car with Animator, but there are some problems.
Assum the object will move from red squre to blue squre.
There are so many ways to move object.
But If you implement this with Unity Animator, the Animator will choose the shortest path (orange line).
Suppose there is a path moving from a red square to a blue square through a green square as shown in the picture above.
When the distances of each point are not equal, if the animation keyframes are distributed as follows 1:1
The speed at which the object moves in the two sections is different.
So, if you want to make constant speed animation when s1 and s2 are not equal,
you should control keyframes to become S1 : S2 = ( t1 - t0 ) : ( t2 - t1 )
Of course, It's possible if you spend a lot of time.
But if the path is curved, It will be very hard to calculate the ratio.
The common issue of problems 1-1 and 1-2 is'curve'.
I was looking for how to express curves in Unity, and I found something called Bezier curves.
First, think of a point that moves a straight line.
There is a straight line and the point M is moving at a constant speed above it.
The trajectory of this point M is drawn as a simple straight line.
At this time, t is a number indicating how far the line segment has been proportionally advanced.
Add another line here and place a point on it that moves like an M.
Then, the original point M is referred to as M0, and the new point is referred to as M1.
The rules for moving M0 and M1 are the same as before.
Here you can draw one more line connecting M0 and M1.
The line naturally moves together when M0 and M1 move.
You can put the point on that line, and let that point be B.
And if you look at the trajectory drawn by point B, you can see that it becomes a curve drawn at a constant speed.
The trajectory drawn by point B is called a quadratic Bezier curve.
Below is the Bezier curve equation for time t.
As you increase the control point, you can create a 3rd, 4th, 5th order .. Bezier curve.
As the control point increases, you can create sophisticated or complex curves,
For this project, I thought that the quadratic Bezier curve was sufficient.
Unity Version : 2019.4.1f โ
There are 2 scripts I will introduce.
- PathGenerator : Script to make followable path the based on Bรฉzier curve.
- PathFollower : Script to follow the path created by "Path Generator" class.
So let's get started.
3-1-1 . You can download the latest released unity package or download this repo.
3-1-2. Import Unity package.
However, the following must be observed.
- The files
PathFollowerGUI.cs
,PathGeneratorGUI.cs
, andPathGeneratorGUILanguage.cs
must be imported into the project, and they should be inAssets/Editor/PathGenerator
.
- The files
PathFollower icon.PNG
,PathFollowerGUI icon.PNG
,PathGenerator icon.PNG
,PathGeneratorGUI icon.PNG
,PathGeneratorGUILanguage icon. PNG
,PG_Anchor.PNG
,PG_End.PNG
,PG_Handler.PNG
,PG_Node.PNG
, andPG_Start.PNG
must be imported into the project, and they should be inAssets/Gizmos/PathGenerator
.
- The files
PathFollowerScriptImg.PNG
andPathGeneratorScriptImg.PNG
must be imported into the project, and they should be inAssets/Resources\PathGenerator\Logo
Create an empty game object in your scene. (And rename it to "Path".)
This object becomes a curved path that can be followed.
Add Path Generator
component to this object.
Path Generator
is largely divided into 6 parts.
Category | Description |
---|---|
Header part | Determine the nature of the path. |
Node part | Shows a list of nodes that determine the origin, waypoint, and destination. |
Angle part | Shows a list of angles that determine the shape of the curve. |
Full Control Part | All nodes and angles can be collectively controlled. |
Rendering part | Created curves can be visualized. |
Editor-related parts | Editor settings for easy curve control |
The part that determines the nature of the Path.
``Path density```` determines how accurately the curve is drawn.
The higher the number, the closer the curve is to the ideal, but too high and the object may behave erratically.
Important point, Path density
must always be greater than or equal to 2!
Recommended values are 30-50.
If the Update path in runtime
item is True
, the path is updated every frame.
Through this, even if the path changes in runtime, it is applied immediately.
However, the amount of computation may increase.
Determines whether to connect the last node and the last node.
Shows a list of nodes that determine the origin, waypoint, and destination
Adds a node to the end of the list.
Remove the selected node.
Edit the selected node.
Shows a list of angles that determine the shape of the curve.
Edit the selected angle.
All nodes and angles can be collectively controlled.
Set the X / Y / Z
values of all angles and nodes in this path to 0.
Average the X / Y / Z
values of all angles and nodes in this path.
Make the X / Y / Z
values of all angles and nodes in this path a specific value.
You can visualize the created curve as shown in the figure below.
There is a bug where the rendering is not displayed normally when the curved path is sharply bent.
If Generate path mesh in runtime
is set to True
, create a mesh that can visualize the created curve.
Texture of the mesh of the lines to be displayed.
If the texture has a pattern like the picture below, it is good to express the flow.
Demo textures located at
/Assets/PathGenerator/DemoScene/Textures/
If you want the texture to repeat, you must set the Wrap Mode
to Repeat
.
Also, if you want to see the Material repeated in the Scene,
You need to turn on Animated Materials
.
The width of the line mesh to be displayed
Scroll speed of the line texture to render. Can be set from -100 to 100.
Transparency of the line texture to be displayed.
Decide how far to draw the line mesh to be expressed. Can be set from 0 to 1
Specifying the render queue order of materials
Editor settings for easy curve control
This mode changes the Transform information (Position, Rotation, Scale) of the current object.
This mode appears when an object is selected in Unity.
This mode allows you to edit the position of nodes and angles, not the current object.
Each node and angle can be edited one by one.
This mode allows you to edit the positions of nodes and angles as a whole, not the current object.
Selecting this mode allows you to control all nodes and angles at once.
This can be useful when resetting the pivot of the path.
If this option is True
, the label is visible in the scene.
If this option is True
, the icon is shown in the scene.
You can switch to Top view mode looking down the scene from above.
You can specify the color of the guidelines.
Use the above functions appropriately to create the path you want.
Add an empty object to move.
This object becomes the object following the path created in 3-2.
Add a "Path Follower" component to that object.
Path Generator
is largely divided into two parts.
Category | Description |
---|---|
movement information part | determine the nature of the movement. |
event part | Defines an event that occurs when a path is completed. |
Define the characteristics of movement.
Specifies the path to move. Just select PathGenerator
in Scene.
If Path
is empty, Path Follower
cannot be moved.
Specifies the movement speed.
The object moves along the given path at this speed.
If you enter a value that is too fast, it may malfunction.
When the distance between the moving object and the next node becomes less than this value,
It determines that the object has arrived at its destination and moves to the next node.
If this value is too small or too large, it may malfunction.
is the rotational speed of the object.
If this value is false
, the object does not move.
If this value is true
, the object will repeat its path infinitely.
It doesn't matter if the path is closed or open.
Defines a method to be executed when the route is completed.
If this value is true
, the method is executed every time the route is completed.
At this time, if object's Is Loop
is true
, the method is not executed forever.
(Because I don't think I've completed the route.)
There may be many examples, but the best example is to create an object that runs along a given track.
I once made a car that runs on a circular track I got from the Asset Store.
With a little modification, you can implement a car that moves naturally even the wheels and steering wheel.
You can express movements between planets like the solar system.
This script also allows you to create circular paths and elliptical orbits like Comet Halley.
Thanks for read! check out my blog too !
- Create issue in this repo
- kau_esc@naver.com
- kimyc1223@gmail.com
- kim.youngchan@yonsei.ac.kr
- ๋ค์์คํ์ด์ค ๋ณ๊ฒฝ (
PathGenerator
>CurvedPathGenerator
) - ์์ ํ์ด์ด๋ผํค ์์
- ์์ํ ๋ฒ๊ทธ ์์
๐บ Unity Curved Path Generator V 2.0
There is an English translation at the top. (์๋จ์ ์์ด ๋ฒ์ญ์ด ์์ต๋๋ค.)
์ ๋ํฐ์์ ์ค๋ธ์ ํธ๋ฅผ ๊ณก์ ๋ฐ ์ง์ ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ผ ์์ง์ด๊ฒ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ผ๊น?
์๋ง ๊ฐ์ฅ ์ฝ๊ณ ์ง๊ด์ ์ธ ๋ฐฉ๋ฒ์ ์ ๋๋ฉ์ด์ ์ ์ฌ์ฉํ๋ ๊ฒ์ผ๊ฒ์ด๋ค.
ํ์ง๋ง ์ ๋๋ฉ์ด์ ์ ํตํ ๊ตฌํ ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ์ ๋ฌธ์ ์ ์ด ์๋ค.
๋นจ๊ฐ ๋ค๋ชจ์์ ํ๋ ๋ค๋ชจ๋ก ์์ง์ด๋ ์ ๋๋ฉ์ด์ ,
์ฆ Position์ ๋ณํ๋ฅผ ์ ๋๋ฉ์ด์ ์ผ๋ก ๋ง๋ ๋ค๊ณ ํ๋ฉด
๊ฒฝ๋ก๋ ์ ๊ทธ๋ฆผ์ฒ๋ผ ๋ฌด์ํ ๋ง์ด ์กด์ฌ ํ ์ ์๋๋ฐ,
์ ๋๋ฉ์ด์ ์์๋ ํญ์ ๊ฐ์ฅ ๋นจ๋ฆฌ ๋ณํ ์ ์๋ ๋ฐฉํฅ (์ฃผํฉ์ ํจ์ค) ์ผ๋ก๋ง ์ ํด์ง๋ค.
๋ง์ฝ ์ ๊ทธ๋ฆผ์ฒ๋ผ ๋นจ๊ฐ ๋ค๋ชจ์์ ์ด๋ก์ ๋ค๋ชจ๋ก, ๊ทธ ํ ํ๋์ ๋ค๋ชจ๋ก ์์ง์ด๋ ํจ์ฐ๊ฐ ์๋ค๊ณ ํ์.
์ด ๋ ๊ฐ ์ง์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๊ฐ ๊ฐ์ง ์๋ค๊ณ ํ ๋,
์ ๋๋ฉ์ด์ ํคํ๋ ์์ด ๋ค์๊ณผ ๊ฐ์ด ๋ถํฌํ๋ค๋ฉด (1:1 ๋ก)
๋ ๋ถ๋ถ์์ ๋ฌผ์ฒด๊ฐ ์์ง์ด๋ ์๋๋ ๋ค๋ฅผ๊ฒ์ด๋ค.
๋ฐ๋ผ์ ์ ์ํฉ์ฒ๋ผ s1๊ณผ s2๊ฐ ๊ฐ์ง ์์ ๋ ์ผ์ ํ ์๋์ ์ ๋๋ฉ์ด์ ์ ๋ง๋ค๊ณ ์ถ๋ค๋ฉด,
S1 : S2 = ( t1 - t0 ) : ( t2 - t1 ) ์ด ๋๋๋ก ํคํ๋ ์์ ์ ์ดํด์ผ ํ๋ค.
๋ฌผ๋ก ์๊ฐ์ ๋ง์ด ํฌ์ํ๋ฉด ๊ฐ๋ฅํ๊ฒ ์ง๋ง,
๊ฒฝ๋ก๊ฐ ๊ตฌ๋ถ๋ฌ์ง๊ฑฐ๋ ๊ทธ ์๊ฐ ๋ง์ ๋น์จ์ ๊ณ์ฐํ๊ธฐ ํ๋ ์ํฉ์์ ๋ถํธ ํ ์ ๋ฐ์ ์๋ค.
์์์ ์ ์ ์๋ ๋ฌธ์ ์ ์ค ๊ณตํต๋ ์ฌํญ์ โ๊ณก์ โ์ด๋ค.
์ด๋ป๊ฒ ํ๋ฉด ๊ณก์ ์ ๋ํ ๋ผ ์ ์์๊น ์ฐพ์๋ณด๋ค๊ฐ, ๋ฒ ์ง์ด ๊ณก์ (Bรฉzier curve)์ด๋ผ๋ ๊ฒ์ ์ฐพ์๋ด์๋ค.
์ผ๋จ ์ง์ ์ ์์ง์ด๋ ์ ์ ์๊ฐํด๋ณธ๋ค.
ํ๋์ ์ง์ ์ด ์๊ณ ๊ทธ ์๋ฅผ ์ M์ด ์ผ์ ์๋๋ก ์ด๋ํ๊ณ ์๋ค.
์ด ์ M์ ๊ถค์ ์ ๋น์ฐํ์ง๋ง ๋จ์ํ ์ง์ ์ผ๋ก ๊ทธ๋ ค์ง๋ค.
์ด๋ t๋ ์ ๋ถ ์๋ฅผ ๋น์จ์ ์ผ๋ก ์ผ๋ง๋ ๋์๊ฐ๋์ง๋ฅผ ๋ํ๋ด๋ ์์น๋ค.
์ฌ๊ธฐ์ ์ ์ ํ๋ ๋ ์ถ๊ฐํ๊ณ ๊ทธ ์์ M์ฒ๋ผ ์ด๋ํ๋ ์ ์ ๋์๋ณธ๋ค.
๊ทธ๋ฆฌ๊ณ ์๋์ ์ M์ M0๋ก, ์๋ก์ด ์ ์ M1์ผ๋ก ํ๋ค.
M0์ M1์ด ์์ง์ด๋ ๊ท์น์ ์ด์ ๊ณผ ๊ฐ๋ค.
M1์ด๋ผ๋ ์ ์ด ํ๋ ๋ ๋์๋ค ํ๋๋ผ๋ ํน๋ณํ ๋ณต์กํด์ง ๊ฒ์ ์๋ค.
์ฌ๊ธฐ์์ M0์ M1์ ์๋ ์ ์ ํ๋ ๋ ๊ทธ์ ์ ์๋ค.
๊ทธ ์ ์ M0์ M1์ด ์ด๋ํ๋ฉด ์์ฐ์ค๋ฝ๊ฒ ํจ๊ป ์์ง์ด๊ฒ ๋๋ค.
๊ทธ ์ ์์ M0๋ M1์ฒ๋ผ ์ผ์ ์๋๋ก ์ด๋ํ๋ ์ ์ ๋์ ์ ์๋ค. ๊ทธ ์ ์ B๋ผ๊ณ ํ์.
๊ทธ๋ฆฌ๊ณ ์ B๊ฐ ๊ทธ๋ฆฌ๋ ๊ถค์ ์ ์ดํด๋ณด๋ฉด, ๊ณก์ ์ด ๋๋ ๋ชจ์ต์ ๋ณผ ์ ์๋ค.
์ B๊ฐ ๊ทธ๋ฆฌ๋ ๊ถค์ ์ 2์ฐจ ๋ฒ ์ง์ด ๊ณก์ (Quadratic Bezier Curve)์ด๋ผ๊ณ ํ๋ค.
์๋๋ ์๊ฐ t์ ๋ํ ๋ฒ ์ง์ด ๊ณก์ ์์ด๋ค.
์กฐ์ ์ ์ ๋๋ฆด์๋ก 3์ฐจ, 4์ฐจ, 5์ฐจ .. ๋ฒ ์ง์ด ๊ณก์ ์ ๋ง๋ค ์ ์๋ค.
์ฐจ์๊ฐ ๋์ด๋ ์๋ก ์ ๊ตํ๊ฑฐ๋ ๋ณต์กํ ๊ณก์ ์ ๋ง๋ค ์ ์์ง๋ง,
์ด๋ฒ ํ๋ก์ ํธ์์๋ 2์ฐจ ๋ฒ ์ง์ด ๊ณก์ ๋ง์ผ๋ก๋ ์ถฉ๋ถํ๋ค๊ณ ์๊ฐํ๋ค.
์๋๋ 3์ฐจ ๋ฒ ์ง์ด ๊ณก์ ์ด๋ค.
Unity ๋ฒ์ : 2019.4.1f ์ด์
์๊ฐํ ์คํฌ๋ฆฝํธ๋ ๋ค์ 2๊ฐ์ง๋ค.
- PathGenerator : ๋ฒ ์ง์ด ๊ณก์ ์ ๊ธฐ๋ฐ์ผ๋ก ๋ฐ๋ผ๊ฐ ์ ์๋ ๊ฒฝ๋ก๋ฅผ ๋ง๋๋ ์คํฌ๋ฆฝํธ.
- PathFollower : "PathGenerator" ํด๋์ค์ ์ํด ์์ฑ๋ ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ฅด๊ธฐ ์ํ ์คํฌ๋ฆฝํธ
3-1-1 . ์ต์ ์ release๋ unity package๋ฅผ ๋ค์ด๋ก๋ ํ๊ฑฐ๋, ์ด repo๋ฅผ ๋ค์ด๋ฐ์ผ๋ฉด ๋๋ค.
3-1-2. ์ ๋ํฐ ํจํค์ง๋ฅผ ์ํฌํธํ๋ค.
๋จ,๋ค์๊ณผ ๊ฐ์ ์ฌํญ์ ๋ฐ๋์ ์ง์ผ์ผํ๋ค.
PathFollowerGUI.cs
,PathGeneratorGUI.cs
,PathGeneratorGUILanguage.cs
๋ผ๋ ํ์ผ์ ํ์์ ์ผ๋ก ํ๋ก์ ํธ์ ์ํฌํธ ๋์ด์ผ ํ๋ฉฐ,Assets/Editor/PathGenerator
๋ผ๋ ํด๋์ ์์ด์ผ ํ๋ค.
PathFollower icon.PNG
,PathFollowerGUI icon.PNG
,PathGenerator icon.PNG
,PathGeneratorGUI icon.PNG
,PathGeneratorGUILanguage icon.PNG
,PG_Anchor.PNG
,PG_End.PNG
,PG_Handler.PNG
,PG_Node.PNG
,PG_Start.PNG
๋ผ๋ ํ์ผ์ ํ์์ ์ผ๋ก ํ๋ก์ ํธ์ ์ํฌํธ ๋์ด์ผ ํ๋ฉฐ,Assets/Gizmos/PathGenerator
๋ผ๋ ํด๋์ ์์ด์ผ ํ๋ค.
PathFollowerScriptImg.PNG
,PathGeneratorScriptImg.PNG
๋ผ๋ ํ์ผ์ ํ์์ ์ผ๋ก ํ๋ก์ ํธ์ ์ํฌํธ ๋์ด์ผ ํ๋ฉฐ,Assets/Resources\PathGenerator\Logo
๋ผ๋ ํด๋์ ์์ด์ผ ํ๋ค.
Scene์ ๋น ๊ฒ์ ๊ฐ์ฒด๋ฅผ ๋ง๋ ๋ค. (๊ทธ๋ฆฌ๊ณ "Path"๋ก ์ด๋ฆ์ ๋ฐ๊พผ๋ค.)
์ด ๊ฐ์ฒด๋ ๋ฐ๋ผ๊ฐ ์ ์๋ ๊ณก์ ๊ฒฝ๋ก๊ฐ ๋๋ค.
์ด ๊ฐ์ฒด์ Path Generator
์ปดํฌ๋ํธ ์ถ๊ฐํ๋ค.
Path Generator
๋ ํฌ๊ฒ 6๊ฐ์ง ๋ถ๋ถ์ผ๋ก ๋๋๋ค.
๋ถ๋ฅ | ์ค๋ช |
---|---|
ํค๋ ํํธ | Path์ ์ฑ์ง์ ๊ฒฐ์ ํ๋ค. |
๋ ธ๋ ํํธ | ์ถ๋ฐ์ง, ๊ฒฝ์ ์ง, ๋์ฐฉ์ง๋ฅผ ๊ฒฐ์ ํ๋ ๋ ธ๋ ๋ฆฌ์คํธ๋ฅผ ๋ณด์ฌ์ค๋ค. |
์ต๊ธ ํํธ | ๊ณก์ ์ ๋ชจ์์ ๊ฒฐ์ ํ๋ ์ต๊ธ ๋ฆฌ์คํธ๋ฅผ ๋ณด์ฌ์ค๋ค. |
์ ์ฒด ์ ์ด ํํธ | ๋ชจ๋ ๋ ธ๋์ ์ต๊ธ์ ์ผ๊ด์ ์ผ๋ก ์ ์ด ํ ์ ์๋ค. |
๋ ๋๋ง ํํธ | ๋ง๋ ๊ณก์ ์ ๊ฐ์ํ ํ ์ ์๋ค. |
์๋ํฐ ๊ด๋ จ ํํธ | ๊ณก์ ์ ์ฝ๊ฒ ์ ์ด ํ ์ ์๋ ์๋ํฐ ์ค์ |
Path์โ ์ฑ์ง์ ๊ฒฐ์ ํ๋ ๋ถ๋ถ.
Path density
๋ ๊ณก์ ์ ์ผ๋ง๋ ์ ํํ๊ฒ ๊ทธ๋ฆด์ง ๊ฒฐ์ ํ๋ค.
์ซ์๊ฐ ๋์์๋ก ์ด์์ ์ธ ๊ณก์ ์ ๊ฐ๊น์ง๋ง ๋๋ฌด ๋์ผ๋ฉด ๊ฐ์ฒด๊ฐ ๋น์ ์์ ์ผ๋ก ์๋ํ ์ ์๋ค.
์ค์ํ ์ ์, Path density
๋ ํญ์ 2 ์ด์์ด์ด์ผ ํ๋ค!
๊ถ์ฅ ๊ฐ์ 30~50.
Update path in runtime
ํญ๋ชฉ์ด True
์ด๋ฉด, ๊ฒฝ๋ก๊ฐ ๋งค frame๋ง๋ค ๊ฐฑ์ ๋๋ค.
์ด๋ฅผ ํตํด ๋ฐํ์์์ ๊ฒฝ๋ก๊ฐ ๋ฐ๋์ด๋, ์ฆ์ ๋ฐ์๋๋ค.
ํ์ง๋ง ์ฐ์ฐ๋์ด ์ฆ๊ฐ ํ ์ ์๋ค.
๊ฐ์ฅ ๋ง์ง๋ง Node์ ๋ Node๋ฅผ ์ฐ๊ฒฐํ ์ง ๊ฒฐ์ ํ๋ค.
์ถ๋ฐ์ง, ๊ฒฝ์ ์ง, ๋์ฐฉ์ง๋ฅผ ๊ฒฐ์ ํ๋ ๋ ธ๋ ๋ฆฌ์คํธ๋ฅผ ๋ณด์ฌ์ค๋ค
๋ฆฌ์คํธ์ ๋์ ๋ ธ๋๋ฅผ ์ถ๊ฐํ๋ค.
์ ํํ ๋ ธ๋๋ฅผ ์ ๊ฑฐํ๋ค.
์ ํํ ๋ ธ๋์ ๊ฐ์ ๋ณ๊ฒฝํ๋ค.
๊ณก์ ์ ๋ชจ์์ ๊ฒฐ์ ํ๋ ์ต๊ธ ๋ฆฌ์คํธ๋ฅผ ๋ณด์ฌ์ค๋ค.
์ ํํ ์ต๊ธ์ ๊ฐ์ ๋ณ๊ฒฝํ๋ค.
๋ชจ๋ ๋ ธ๋์ ์ต๊ธ์ ์ผ๊ด์ ์ผ๋ก ์ ์ด ํ ์ ์๋ค.
์ด ๊ฒฝ๋ก์ ๋ชจ๋ ์ต๊ธ๊ณผ ๋
ธ๋์ X/Y/Z
๊ฐ์ 0์ผ๋ก ๋ง๋ ๋ค.
์ด ๊ฒฝ๋ก์ ๋ชจ๋ ์ต๊ธ๊ณผ ๋
ธ๋์ X/Y/Z
๊ฐ์ ํ๊ท ๊ฐ์ผ๋ก ๋ง๋ ๋ค.
์ด ๊ฒฝ๋ก์ ๋ชจ๋ ์ต๊ธ๊ณผ ๋
ธ๋์ X/Y/Z
๊ฐ์ ํน์ ๊ฐ์ผ๋ก ๋ง๋ ๋ค.
์๋ ๊ทธ๋ฆผ์ฒ๋ผ ๋ง๋ ๊ณก์ ์ ๊ฐ์ํ ํ ์ ์๋ค.
๊ณก์ ๊ฒฝ๋ก๊ฐ ๊ธ๊ฒฉํ ๊บพ์ผ ๊ฒฝ์ฐ, ๋ ๋๋ง์ด ์ ์์ ์ผ๋ก ํํ๋์ง ์๋ ๋ฒ๊ทธ๊ฐ ์๋ค.
Generate path mesh in runtime
์ด True
์ผ ๊ฒฝ์ฐ, ๋ง๋ ๊ณก์ ์ ๊ฐ์ํ ํ ์ ์๋ mesh๋ฅผ ๋ง๋ ๋ค.
ํํํ ๋ผ์ธ์ mesh์ Texture.
Texture๊ฐ ์๋ ๊ทธ๋ฆผ์ฒ๋ผ ํจํด์ ๊ฐ์ง๊ณ ์์ ๊ฒฝ์ฐ, ํ๋ฆ์ ํํํ๊ธฐ ์ข๋ค.
/Assets/PathGenerator/DemoScene/Textures/
์ ์์นํ ๋ฐ๋ชจ์ฉ ํ ์ค์ฒ
ํ
์ค์ฒ๊ฐ ๋ฐ๋ณต๋๊ธธ ์ํ๋ค๋ฉด, ๋ฐ๋์ Wrap Mode
๋ฅผ Repeat
๋ก ์ค์ ํด์ผํ๋ค.
๋ํ, Scene์์๋ ํด๋น Material์ด ๋ฐ๋ณต๋๋๊ฒ์ ๋ณด๊ณ ์ถ๋ค๋ฉด
Animated Materials
๋ฅผ ์ผ์ฃผ์ด์ผ ํ๋ค.
ํํํ ๋ผ์ธ mesh์ ๋๋น
ํํํ ๋ผ์ธ texture์ ์คํฌ๋กค ์๋. -100 ~ 100๊น์ง ์ค์ ๊ฐ๋ฅ.
ํํํ ๋ผ์ธ texture์ ํฌ๋ช ๋.
ํํํ ๋ผ์ธ mesh๋ฅผ ์ด๋๊น์ง ๊ทธ๋ฆด์ง ๊ฒฐ์ . 0 ~ 1๊น์ง ์ค์ ๊ฐ๋ฅ
Material์ render queue ์์ ์ง์
๊ณก์ ์ ์ฝ๊ฒ ์ ์ด ํ ์ ์๋ ์๋ํฐ ์ค์
ํ์ฌ ์ค๋ธ์ ํธ์ Transform ์ ๋ณด(Position, Rotation, Scale)๋ฅผ ๋ณ๊ฒฝ ํ๋ ๋ชจ๋์ด๋ค.
๊ธฐ์กด Unity์์ ์ค๋ธ์ ํธ๋ฅผ ์ ํํ์ ๋ ๋ํ๋๋ ๋ชจ๋์ด๋ค.
ํ์ฌ ์ค๋ธ์ ํธ๊ฐ ์๋, ๋ ธ๋์ ์ต๊ธ๋ค์ ์์น๋ฅผ ํธ์ง ํ ์ ์๋ ๋ชจ๋์ด๋ค.
๊ฐ ๋ ธ๋์ ์ต๊ธ์ ํ๋์ฉ ํธ์ง ํ ์ ์๋ค.
ํ์ฌ ์ค๋ธ์ ํธ๊ฐ ์๋, ๋ ธ๋์ ์ต๊ธ๋ค์ ์์น๋ฅผ ์ ์ฒด์ ์ผ๋ก ํธ์ง ํ ์ ์๋ ๋ชจ๋์ด๋ค.
์ด ๋ชจ๋๋ฅผ ์ ํํ๋ฉด ์ ์ฒด ๋ ธ๋์ ์ต๊ธ์ ํ ๋ฒ์ ์ ์ด ํ ์ ์๋ค.
path์ pivot์ ์ฌ์ค์ ํ ๋ ์ ์ฉํ๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
์ด ์ต์
์ด True
์ด๋ฉด, Scene์์ Label์ด ๋ณด์ฌ์ง๋ค.
์ด ์ต์
์ด True
์ด๋ฉด, Scene์์ icon์ด ๋ณด์ฌ์ง๋ค.
Scene์ ์์์ ๋ด๋ ค๋ค๋ณด๋ Top view ๋ชจ๋๋ก ์ ํ ํ ์ ์๋ค.
๊ฐ์ด๋๋ผ์ธ์ ์์์ ์ง์ ํ ์ ์๋ค.
์ ๊ธฐ๋ฅ๋ค์ ์ ์ ํ ์ฌ์ฉํ์ฌ ์ํ๋ path๋ฅผ ๋ง๋ค๋ฉด ๋๋ค.
์์ง์ผ ๋น ์ค๋ธ์ ํธ๋ฅผ ์ถ๊ฐํ๋ค.
์ด ๊ฐ์ฒด๋ 3-2์์ ๋ง๋ ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ผ๊ฐ๋ ์ค๋ธ์ ํธ๊ฐ ๋๋ค.
๊ทธ ๊ฐ์ฒด์ "Path Follower" ์ปดํฌ๋ํธ๋ฅผ ์ถ๊ฐํ๋ค.
Path Generator
๋ ํฌ๊ฒ 2๊ฐ์ง ๋ถ๋ถ์ผ๋ก ๋๋๋ค.
๋ถ๋ฅ | ์ค๋ช |
---|---|
์์ง์ ์ ๋ณด ํํธ | ์์ง์์ ์ฑ์ง์ ๊ฒฐ์ ํ๋ค. |
์ด๋ฒคํธ ํํธ | path๋ฅผ ์์ฃผํ์ ๋ ๋ฐ์ํ๋ ์ด๋ฒคํธ๋ฅผ ์ ์ํ๋ค. |
์์ง์์ ํน์ฑ์ ์ ์ํ๋ค.
์์ง์ผ path๋ฅผ ์ง์ ํ๋ค. Scene์ ์๋ PathGenerator
๋ฅผ ์ ํํ๋ฉด ๋๋ค.
Path
๊ฐ ๋น์ด์์ ๊ฒฝ์ฐ, Path Follower
๋ ์์ง์ผ ์ ์๋ค.
์์ง์ผ ์๋๋ฅผ ์ง์ ํ๋ค.
๋ฌผ์ฒด๋ ์ด ์๋๋ก ์ฃผ์ด์ง path๋ฅผ ๋ฐ๋ผ ์์ง์ธ๋ค.
๋๋ฌด ๋น ๋ฅธ ๊ฐ์ ์ ๋ ฅํ๋ฉด, ์ค์๋ํ ์ ์๋ค.
์์ง์ด๋ ๋ฌผ์ฒด์ ๋ค์ ๋ ธ๋ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๊ฐ ์ด ๊ฐ ์ดํ๋ก ๋ ๊ฒฝ์ฐ,
๋ฌผ์ฒด๊ฐ ๋ชฉ์ ์ง์ ๋์ฐฉํ๋ค๊ณ ํ๋จํ์ฌ ๋ค์ ๋ ธ๋๋ก ์์ง์ธ๋ค.
์ด ๊ฐ์ด ๋๋ฌด ์๊ฑฐ๋ ํด ๊ฒฝ์ฐ, ์ค์๋ ํ ์ ์๋ค.
๋ฌผ์ฒด์ ํ์ ์๋์ด๋ค.
์ด ๊ฐ์ด false
์ด๋ฉด, ๋ฌผ์ฒด๊ฐ ์์ง์ด์ง ์๋๋ค.
์ด ๊ฐ์ด true
์ด๋ฉด, ๋ฌผ์ฒด๊ฐ ๊ฒฝ๋ก๋ฅผ ๋ฌดํํ ๋ฐ๋ณตํด์ ์์ง์
๋๋ค.
๊ฒฝ๋ก๊ฐ ๋ซํ๊ฒฝ๋ก์ธ์ง, ์ด๋ฆฐ๊ฒฝ๋ก์ธ์ง์๋ ์๊ด์์ต๋๋ค.
๊ฒฝ๋ก๋ฅผ ์์ฃผํ์ ๋, ์คํ์ํฌ ๋ฉ์๋๋ฅผ ์ ์ํ๋ค.
์ด ๊ฐ์ด true
์ด๋ฉด, ๊ฒฝ๋ก๋ฅผ ์์ฃผํ์ ๋ ๋ง๋ค ๋ฉ์๋๋ฅผ ์คํ์ํจ๋ค.
์ด๋, ๋ฌผ์ฒด์ Is Loop
๊ฐ true
์ผ ๊ฒฝ์ฐ, ํด๋น ๋ฉ์๋๊ฐ ์์ํ ์คํ๋์ง ์๋๋ค.
(๊ฒฝ๋ก๋ฅผ ์์ฃผํ๋ค๊ณ ์๊ฐํ์ง ์๊ธฐ ๋๋ฌธ์ด๋ค.)
๋ง์ ์๊ฐ ์์ ์ ์์ง๋ง ๊ฐ์ฅ ์ข์ ์๋ ์ฃผ์ด์ง ํธ๋์ ๋ฐ๋ผ ๋ฌ๋ฆฌ๋ ๊ฐ์ฒด๋ฅผ ๋ง๋๋ ๊ฒ์ด๋ค.
์์ ์คํ ์ด์์ ๋ฐ์ ์ํ ํธ๋์ ๋ฌ๋ฆฌ๋ ์๋์ฐจ๋ฅผ ๋ง๋ ์ ์ด ์๋ค.
๋ณธ ์คํฌ๋ฆฝํธ๋ฅผ ์ฝ๊ฐ ์์ ํ๊ณ ์์ฉํ์ฌ ๋ฐํด์ ํธ๋ค๊น์ง ์์ฐ์ค๋ฝ๊ฒ ์์ง์ด๋ ์๋์ฐจ๋ฅผ ๊ตฌํํ ์ ์๋ค.
ํ์๊ณ์ ๊ฐ์ ํ์ฑ ๊ฐ์ ์์ง์์ ํํํ ์ ์๋ค.
์ด ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ฉด ํผ๋ฆฌ ํ์ฑ๊ณผ ๊ฐ์ ํ์ ๊ถค๋๋ฅผ ์์ฑํ ์ ๋ ์๋ค.
์ฝ์ด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ์ ๋ธ๋ก๊ทธ๋ ํ์ธํด๋ณด์ธ์!
- ์ด repo ์ด์ ํ์ด์ง์ ์ด์๋ฅผ ๋ฑ๋กํ์๋ฉด ๋ฉ๋๋ค
- kau_esc@naver.com
- kimyc1223@gmail.com
- kim.youngchan@yonsei.ac.kr