国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Godot4 實現(xiàn)自動尋路 2D C#版

2023-05-17 14:20 作者:CG游戲  | 我要投稿

1.添加節(jié)點:

????NavigationRegion2D(2D導(dǎo)航地圖)

????Sprite2D(要移動的元素,圖片替代)

????Line2D(顯示路徑用)


2.代碼正文:

????float speed = 400;//移動速度

???? NavigationRegion2D navmesh;

???? Rid map;

???? bool isAc = false;

???? public Vector2 dhzb = new Vector2(0, 0);//要導(dǎo)航的終點坐標(biāo)

???? Line2D line;

???? List<Vector2> path;

???? Vector2 start_position;//起點

????Sprite2D spdh;//開始點


// Called when the node enters the scene tree for the first time.

public override void _Ready()

{

???? CallDeferred("setup_navserver");

???? line = GetNode<Line2D>("Line2D");

???? start_position = GetNode<Sprite2D>("SPDMD").Position;

???? spdh = GetNode<Sprite2D>("SPDH");

???? navmesh = GetNode<NavigationRegion2D>("Navmesh");

}


// Called every frame. 'delta' is the elapsed time since the previous frame.

public override void _Process(double delta)

{

???? if (isAc)

???? {

???????? var walk_distance = speed *(float)delta;

???????? move_along_path(walk_distance);

???? }

}

//開始導(dǎo)航

public void SetDaoHang(Vector2 dhzb)

{

???? //start_position = start_position - pianyi;

???? spdh.Position = start_position;

???? line.ClearPoints();

???? path = NavigationServer2D.MapGetPath(map, spdh.Position, dhzb, true).ToList();

???? for (int i = 0; i < path.Count; i++)

???? {

???? line.AddPoint(path[i]);

???? }

???? path.RemoveAt(0);

???? isAc = true;

}

#region? 導(dǎo)航函數(shù)

//初始化

private void setup_navserver()

{

???? map = NavigationServer2D.MapCreate();

???? NavigationServer2D.MapSetActive(map, true);

???? //create a new navigation region and add it to the map

???? var region = NavigationServer2D.RegionCreate();//

???? NavigationServer2D.RegionSetTransform(region, Transform2D.Identity);//

???? NavigationServer2D.RegionSetMap(region, map);//

???? //sets navigation mesh for the region

???? NavigationServer2D.RegionSetNavigationPolygon(region, navmesh.NavigationPolygon);

???? // wait for Navigation2DServer sync to adapt to made changes

}

//移動函數(shù)

private void move_along_path(float distance)

{

???? var last_point = spdh.Position;

???? for (int i = 0; i < path.Count; i++)

???? {

???????? float distance_between_points = last_point.DistanceTo(path[0]);

???????? if (distance <= distance_between_points)

???????? {

???????????? //The position to move to falls between two points.

???????????? spdh.Position = last_point.Lerp(path[0], distance / distance_between_points);

???????????? //isAc = false;

???????????? return;

???????? }

???????? distance -= distance_between_points;

???????? last_point = path[0];

???????? //line.AddPoint(last_point);

???????? path.RemoveAt(0);

???? }

???? spdh.Position = last_point;

???? if (path.Count == 0)

???? {

???? ???? isAc = false;

???? }

}

#endregion


//外部調(diào)用函數(shù)

public void ZBSetDH(string szb)

{

????SetDaoHang(GetNode<Sprite2D>(szb).Position);

}


Godot4 實現(xiàn)自動尋路 2D C#版的評論 (共 條)

分享到微博請遵守國家法律
山阳县| 钟山县| 乌恰县| 通州区| 牡丹江市| 保靖县| 晋中市| 临汾市| 新沂市| 临漳县| 和林格尔县| 什邡市| 宜章县| 林周县| 慈利县| 宜州市| 年辖:市辖区| 西城区| 普安县| 东平县| 黔西县| 嘉义市| 都兰县| 拉孜县| 郯城县| 莱阳市| 宽甸| 苍溪县| 辉县市| 垦利县| 固始县| 仲巴县| 梅河口市| 财经| 梅州市| 禹城市| 胶州市| 专栏| 法库县| 茌平县| 固安县|