'전체 글'에 해당되는 글 514건

  1. 2024.02.22 [Godot] Path2D PathFollow2D

[Godot] Path2D PathFollow2D

Godot 2024. 2. 22. 22:10 |
반응형

정해진 길을 따라 움직이는 오브젝트를 만들어 보자.

 

Path2D를 추가하고 툴 버튼을 이용해 path를 그린다.

 

PathFollow2D, Sprite2D를 추가한다. PathFollow2D는 Path2D의 자식 노드이어야 한다.

 

Node2D에 스크립트를 추가한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using Godot;
 
public partial class Control : Node2D
{
    public PathFollow2D follower;
 
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        follower = GetChild<Path2D>(0).GetChild<PathFollow2D>(0);
    }
 
    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
        follower.ProgressRatio += (float)delta;
    }
}
 

 

위와 같이 코드를 작성한다.

 

실행하면 스프라이트가 Path를 따라 움직인다.

 

반응형
Posted by J-sean
: