Rocket Tower Implementation
Author: Yashwant Patel
Problem:
For the current week one of our focuses was implementing more towers. One of the towers we designed shoots a rocket along the closest path that it has been placed. As with anything there are multiple ways of implementing the rocket movement, but two of the main ways that were thought of right away are navmesh and spline movement. Navmesh is usually the go to solution for any AI like units, but as discussed before this is a bit overkill for our needs, so why not just use the splines already in place to move our rocket along it? The spline movement component currently only moves an Actor in the forward direction whereas the rocket would need to move in the opposite direction, so that will need to be implemented. Also, the movement of the Actor is controlled via a distance variable that is increment every frame depending on the speed variable and delta time, but it doesn't directly correlate with the length of the spline, so how would we calculate at what distance along the spline the rocket needs to spawn? If these two things aren't addressed then the player would have access to a tower that spawns rockets at the beginning of the path and moves towards the Island Core like an enemy which is like Mario running away from the princess trying to reach the beginning of the game. Another problem is the player needs to know which spline the rocket will travel across when they are trying to place the tower, but a spline cannot be highlighted or shown to the player since they aren't visible during runtime. Without knowing which lane the rocket will go down when the player is choosing where to place the tower is frustrating, because they have to try and eyeball which lane the tower is closest to. If they are wrong then that sucks, because the towers can't be sold.
Solution:
To move an Actor backwards along the spline was a simple thing to implement. The Actor is moved along the spline by getting the world transform along the spline depending on the distance variable. The distance variable is incremented every frame depending on the speed and delta which inherently makes the Actor move forward, so in order to move backwards you simply just decrement from the distance. In order to have control of the direction a float is multiplied in order influence the direction.
After looking at the API and some fiddling I stumbled upon the GetDistanceAlongSplineAtSplineInputKey(args) which essentially gets the distance at the spline location. For getting the spline location there is a handy function FindInputKeyClosestToWorldLocation(args) which lets me get the location on the spline, so that problem has been solved. Now how to show which spline the rocket tower will fire rockets at?
One way could be to dynamically spawn spheres at the nodes along the spline then connect them with a line renderer (or whatever Unreal has similar to this) and show the closest "spline" when the player is trying to place the tower. This would be a nice thing to have, but the hardest solution isn't always the best one. The second solution that came to mind was having an arrow which would point to where the closest spline was and the location on that spline at which the rocket would spawn. This seemed like the most elegant solution, so this is what was implemented.
Comments
Post a Comment