- Unreal Engine 4 AI Programming Essentials
- Peter L. Newton Jie Feng
- 242字
- 2021-07-16 12:48:40
Adding the challenge
Now, we will add line traces to the AI character. In our demonstration, we will use traces to detect the wall in front of the pawn. Other examples of using traces in the AI include Line of Sight checking, getting surface rotation, and getting nearby actors.
Let's go back to Unreal Engine Level Editor and look within Content Browser. Perform the following steps:
- Rename our
MyController
blueprintHero
; this will act as the player in this scenario. - Open our
Hero
blueprint and go to the EventGraph section. - Now, remove every node except the Event Tick and Move to Location nodes. We will replace these with new blueprint scripting:
Blueprint after removing unnecessary nodes
- Pull from the return exec pin on the Event Tick node and create a Delay node.
- Set the Duration value to .05 so that it will update relatively fast.
- Now, we have to get the location from the pawn to create line traces. We will also use the right vector to face the pawn to the right from the pawn's current rotation when the collision ahead is detected.
- Right-click on EventGraph and search for Get Controlled Pawn.
- From the Return Value pin of Get Controlled Pawn, pull the Get Actor Location node.
- From the Return Value pin of GetActorLocation, pull a vector and then drop it in an empty area.
- Search for LineTraceByChannel, which is located under the Collision category, as shown in the following screenshot:
推薦閱讀
- 24小時學會電腦組裝與維護
- Raspberry Pi 3 Cookbook for Python Programmers
- BeagleBone By Example
- 基于ARM的嵌入式系統和物聯網開發
- 電腦組裝、維護、維修全能一本通(全彩版)
- 嵌入式系統設計教程
- 筆記本電腦維修不是事兒(第2版)
- 龍芯自主可信計算及應用
- 電腦橫機使用與維修
- Spring Cloud實戰
- Deep Learning with Keras
- 微服務架構基礎(Spring Boot+Spring Cloud+Docker)
- 筆記本電腦的結構、原理與維修
- 分布式存儲系統:核心技術、系統實現與Go項目實戰
- The Reinforcement Learning Workshop