官术网_书友最值得收藏!

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:

  1. Rename our MyController blueprint Hero; this will act as the player in this scenario.
  2. Open our Hero blueprint and go to the EventGraph section.
  3. 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

  4. Pull from the return exec pin on the Event Tick node and create a Delay node.
  5. Set the Duration value to .05 so that it will update relatively fast.
  6. 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.
  7. Right-click on EventGraph and search for Get Controlled Pawn.
  8. From the Return Value pin of Get Controlled Pawn, pull the Get Actor Location node.
  9. From the Return Value pin of GetActorLocation, pull a vector and then drop it in an empty area.
  10. Search for LineTraceByChannel, which is located under the Collision category, as shown in the following screenshot:
主站蜘蛛池模板: 陆丰市| 肇东市| 营口市| 崇仁县| 都昌县| 灵石县| 沿河| 东兰县| 兴宁市| 开化县| 固原市| 北票市| 焉耆| 锡林郭勒盟| 沁水县| 车致| 安阳市| 昌都县| 南和县| 明溪县| 百色市| 大新县| 巫山县| 自贡市| 盐津县| 台江县| 丰县| 涟水县| 抚远县| 章丘市| 丹阳市| 兴安盟| 鄂伦春自治旗| 平邑县| 奈曼旗| 梨树县| 甘德县| 荔浦县| 沾化县| 舒兰市| 和静县|