I took an old AI script I wrote for Extinction Plan from a tutorial in JavaScript, and I translated it over to C#, changing some of the unneeded and convoluted lines along the way. This included replacing an entire Vector3.Slerp formula for calculating object rotation based on target rotation with the much simpler transform.LookAt. This transition was done because of a 3D rotation issue I was experiencing when the object was moved around the grid spaces. For some reason when set to move, the character object would rotate 90 degrees onto its back and then move; but would never right itself before coming to a stop.
So I replaced all of the headache-inducing calculation lines with the much simpler idea of simply having the character use the LookAt method to achieve its rotation, and now even during movement the character doesn't rotate on the 3D plane, only the 2D one. This was most easily accomplished by having the character create a currentTarget, which is found by looking for GameObjects with a specific tag, and then rotating to face them. This should make it easy for characters to turn to specified locations when casting spells on other characters, simply by creating an empty game object that they will use as a reference location while a casting bool is active. Then having them simply look back to the boss when they are no longer fixated on casting automatically using a simple if/else statement.
Movement has gone through a couple iterations. At first, I was going to allow the characters to move to a relative location based on the player creating a waypoint for them, and then having a movement bool become active which told the character to move to that location. Once the character moved to the location, they would hit a collider that told the movement bool to flag as inactive and the character would stop moving; and the waypoint would be destroyed. This worked okay, but the characters always seemed to move in a strange arc towards the waypoint, although it was a small arc and they would always reach the correct position one way or another. However, this method created a larger issue: The characters were no longer on a grid-space. That meant that it would be more difficult to keep characters from overlapping, and being able to target specific characters with direct spells. It also gave way to a future issue of allowing all the characters to sit in locations that would be difficult for the boss enemies to target them (like in the center of 4 grid spaces).
To combat the movement problems, I figured it would be better to simply write a new script, that allowed the character to move around on a grid, using the predefined size of the grid spaces as a reference point. Since grids are inherently the same size throughout, it was easy to simply make the movement controls 1 unit at a time in the horizontal and vertical directions. This meant instead of telling my characters to go to a relative position based on a waypoint, I was simply telling them to move 1 unit left or right, up or down. This worked out perfect, and now the characters effectively stay on grid spaces.
No comments:
Post a Comment