Freitag, 25. November 2016

Developer Diary 44 Why this Code Changed my Life



Soldiers patrol through the maze. They are as large as buildings and destroy everything in their way. A tree is no obstacle to them, neither is a house, a tower or any kind of structure. But because of their size they are able to travel vast distances in a short amount of time.

The distance is too large for any navigation volume to work properly. So after weeks and months of trying to figure out a way to deal with AI while excluding navigation volumes I finally found the answer:

I set the AI movement in the Behavior tree to "Move Directly To". This way of movement causes an AI to move directly towards a specified goal, but it will also cause the AI to float, or fly through the air if it is following a player character which is currently moving up or down hill. The AI may also get stuck when colliding with obstacles, but since the soldiers are too large to collide with anything this is not a concern.

By implementing a Line Trace By Channel that starts 500cm above the pawn location and extends 5000 cm below the pawn location and ignores the pawn, all other blueprints and objects except the landscape itself, it is possible to get the landscape Z coordinate at the pawn's location. This Z value can now be used to "tie the AI down" to the desired location by using the "Set Actor Location" Node.

The AI will now move through the landscape while staying on the ground and follow the player everywhere independent of any navigation volume. If it collides with trees or objects such as houses, a collision volume near the pawn's base will trigger a Blueprint containing a destructible mesh to spawn at the object's location, identical to the original object in size and appearance. By applying radial damage in the Event Graph of the blueprint the mesh gets destroyed. These two little tricks save FPS and revolutionize AI navigation for large creatures.

I'm happy!

S.M





Keine Kommentare:

Kommentar veröffentlichen