Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    Unreal Engine AI Vehicle Tutorial 8: Integrating Road Network with Vehicle AI

    blog thumbnail

    Introduction

    In this tutorial, we will integrate the Vehicle AI and the Road Network from the previous tutorial. The Road Network tool allows us to create a road layout from the editor, while Vehicle AI enables the vehicles to follow this path and avoid obstacles. This comprehensive guide will walk you through the integration of these systems in a traffic simulation project.

    Prerequisites

    Before we begin the integration, ensure you have the necessary plugins:

    1. Road Network Tool Plugin.
    2. Algorithm Plugin.

    If you have already created the Road Network Tool plugin, copy it from the road project plugin directory and paste it into the traffic tutorial plugin directory. After pasting it, delete the Intermediate and Binaries folders from both the Road Network Tool plugin and the Algorithm Plugin.

    Project Setup

    1. Open traffic_tutorial.sln in Visual Studio and right-click to generate the project files.

    2. Inside the project, locate the Road Actor class under the Road Network Tool directory. Open the RoadActor.h and RoadActor.cpp files.

    3. Locate the GenerateMeshFromPoints function, which needs to be modified. We are going to make it so that the vehicles ignore the road as an obstacle.

      SetCollisionProfileName(TEXT("Custom"));
      CollisionResponseChannel = ECC_Visibility;
      CollisionResponse = ECR_Ignore; 
      
    4. With this modification, the vehicle will now ignore the road mesh component as an obstacle.

    Creating a Road Network

    1. In the editor, create a new Road Network with the desired parameters (e.g., Thickness: 5, Width: 400).
    2. Play the scene and ensure that the road network is functional.
    3. To obtain the hit location from the line trace, you’ll need to check if the actor tag is equal to "Floor".

    Finding Path Nodes

    Now we need another pathfinding algorithm to get the vehicle to follow the road network. Start by creating a new struct to handle FPathNode, which represents the intersection points on the road.

    1. Create a folder named Component and extract the new pathfinding algorithm for incorporation.
    2. Include the required headers and create a RoadMeshGenerator.h and RoadMeshGenerator.cpp.

    Modifying the Road Actor

    1. Copy relevant functions from the RoadActor and paste them into the new mesh generator.
    2. Update function parameters to match the new mesh generator’s requirements.

    Road Mesh Generation

    Proceed to the GenerateRoadMesh function, incorporating settings for the road thickness and its material.

    RoadActorWidth = RoadActor->GetRoadWidth();
    

    This will ensure that the newly generated road matches the specified parameters.

    Material Setup

    Create a new material named M_Road. Set the color, roughness, and convert necessary parameters.

    1. Assign the created material to your Road Mesh when generating the road to ensure a visual representation within your scene.

    Implementing AI Logic

    Transition to fine-tuning the AI for vehicles:

    1. Modify how the vehicle identifies its target location concerning the road mesh.
    2. Adjust speed control mechanisms based on vehicle proximity to target nodes.

    Visualizing Paths

    Create a dynamic material instance to visualize the default path and alternative routes. Implement logic to toggle the visibility of these paths during gameplay.

    Collision and Obstacle Avoidance

    Utilize the motion trajectory component to detect obstacles and implement avoidance routines.

    1. Change the collision settings tailored for the vehicle AI to recognize when it comes close to obstacles.
    2. Ensure the AI recalibrates its path based on detected movements.

    Conclusion

    At this point, you should have a working system where vehicles can navigate a road network while dynamically avoiding obstacles and other vehicles. By integrating the Vehicle AI with the Road Network, you enhance the realism and functionality of your simulation.

    Keywords

    Road Network, Vehicle AI, Integration, Unreal Engine, Pathfinding, Collision Detection, Dynamic Material, Obstacle Avoidance, Traffic Simulation

    FAQ

    Q: What is the primary function of the Road Network tool?
    A: The Road Network tool allows developers to create road layouts easily within the Unreal Engine editor.

    Q: How does the Vehicle AI interact with the road network?
    A: The Vehicle AI can follow the generated road paths and adaptively avoid obstacles during navigation.

    Q: What changes were made to ensure vehicles ignore the road as an obstacle?
    A: The collision profile of the road mesh was modified to ignore visibility channels, allowing vehicles to pass over or across the road without detecting it as an obstacle.

    Q: How can I visualize the pathfinding process for vehicles?
    A: You can create a dynamic material instance that highlights the vehicle's path and any alternative routes, enhancing the visual feedback in your scene.

    Q: What additional functionality was introduced for detecting obstacles?
    A: The motion trajectory component was utilized to predict vehicle movements and detect obstacles dynamically during gameplay.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like