What to Expect
In the third part of this tutorial series we will focus on string manipulation. Now that we have created a navmesh and have our unit moving across the navmesh, we will want to spruce up the interactivity. By using some simple but clever string manipulation, we will generate random start and end points for our tanks to move from and to.
Knowing how to manage strings is an essential skill for both programming and flow control. In this tutorial we will use the variables we created in part 2 and generate strings to call those variables randomly.
- In Level Flow, create logic to generate random start and end point numbers.
- Add additional logic to ensure both endpoint and start point are not the same.
- Now that we have 2 unique numbers to work with, create the required strings for spawn position, goal position, and the goals unit variable name.
- Using these Generated Names, Spawn the Tank on my_spawn_pos, Set the destination on my_goal_pos and move the tank.
- Test the Results. Upon clicking, tanks should now spawn at random flags and move to random goals. Note the fact that your tanks make instant changes of direction.
Edit the Bot. NavTag_Layer “use_channel = true” to use the spline trajectories to smooth the motion.
- Test again. Note the smoothed turning of the tanks now.