How do i make Enemy Pathways on my procedurally generated terrain, for my Tower Defense Game?

Wassup guys. I want to ask for guidance on how to make waypoints for my enemies to reach my tower. The terrain I made for the game is procedurally generated on runtime, and players can spawn their tower anywhere on the terrain. Now I have no idea how I can make pathways for enemies to get to the tower, so I would appreciate it if you could give me ideas on how to please. I would also like to make multiple pathways also, so the enemies don’t seem robotic… Thank you!

I Have not done anything yet. I am hoping you guys can set me in the right direction.

4

One thing you might look into is various procedural path generation algorithms, such as maze algorithms. This way you can generate procedural paths all around your procedural terrain. You would then have the enemies move along those paths towards the destination. An algorithm you can use for that could be something like A-star pathfinding.

The reason tower defense games take place on grid like levels is so pathfinding is easy. A-star is a grid based path finding system, so it works well. Gerry Schmitz’s comment is another example of a good way to do it. The benefit of using the maze algorithms is that you can generate some interesting and dynamic paths on a grid like plane on top of your procedural terrain so that you can still maintain that feature.

If you really want to avoid a grid based system, you might be able to look into recast vision. You can have the enemy’s base movement be towards the target. Then, have a series of ray’s be cast out to form a view field that can detect towers, the emeries will be programmed to avoid the towers if it gets to close to it. A simple way would be compare the angle of the tower to the enemy and have it turn away from it. This will allow you to have the towers placed anywhere and the enemies to have “custom” paths.

Well, there are several solutions for this task.

1- You can use the navigation system in Unity to send your enemies toward the target location. First, set up your terrain with the navigation system to define walkable and non-walkable areas. There are plenty of tutorials available on the internet and YouTube.

2- You can create the path manually and tell your enemies which path to take to attack your castle. In the first method, the navigation system automatically selects the shortest path to reach the target, but in this method, you can assign any path to any enemy and have them choose a path randomly.

To do this, you just need to create an array of path points:

public Transform[] path1Point;
public Transform[] path2Point;

Then, assign this array in the editor.

Note: Make sure to add the path points to the array in order, starting with point 0, then point 1, point 2, and so on until the last point.

You can then determine that the enemy randomly follows one of the paths. Create an array of positions for the random path and assign it:

Transform[] randomPath = path1Point;
if (Random.Range(0, 2) == 1)
    randomPath = path2Point;
Vector3[] randomPathPoints = new Vector3[randomPath.Length];
for (int i = 0; i < randomPath.Length; i++)
{
    randomPathPoints[i] = randomPath[i].position;
}

Now you have selected a random path for the enemy, and you just need to tell the enemy to move toward the target using this path.

You can instruct them to first move toward the first member of the random path array, and when they reach that point, they should move to the second member, then the third, and continue this way until they reach the castle.

This code hasn’t been tested, but it should work theoretically:

public float moveSpeed = 0.05f;
public Transform[] path1Point;
public Transform[] path2Point;
private Vector3[] randomPathPoints;

private Vector3 targetPos;
private int _currentPointPathIndex = 0;

void Start()
{
    Transform[] randomPath = path1Point;
    if (Random.Range(0, 2) == 1)
        randomPath = path2Point;
    randomPathPoints = new Vector3[randomPath.Length];
    for (int i = 0; i < randomPath.Length; i++)
    {
        randomPathPoints[i] = randomPath[i].position;
    }

    targetPos = randomPathPoints[_currentPointPathIndex];
}

private void Update()
{
    if (Vector3.Distance(transform.position, targetPos) > 0.5f)
    {
        // move to targetPos
        transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed);
        transform.LookAt(targetPos);
    }
    else
    {
        if (_currentPointPathIndex < randomPathPoints.Length - 1)
            _currentPointPathIndex++;
        targetPos = randomPathPoints[_currentPointPathIndex];
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật