An other weekend passed, so an other update is in order π
The planning for this weekend was to add an other magic effect, a targeting system, GUI element reflecting the target and fix some of the animations.
Targeting System :
As it is now we can freely shoot fireballs and hope we hit our target. But for our next skill we actually need to focus on a target, thus it was time to create a nice targeting system. This actually took several tries to get it right, or at least, we hope it’s right now π
The first iteration of the target system worked like this : As our characters have a FieldOfView that helps with detecting if an object can actually be seen by the character I thought this would be a nice point to start with. Though pretty soon I found out that you can only check of a certain gameObject’s position is within the FieldOfView vertex. To prevent checking of all objects I made a matching mesh collision so that we could refine the scope of objects to check. When an object collides we then check if the object is within the FieldOfView vertex so we know that we can actually see it as well. For example a target around a corner would generate a collision but we would not be able to see it. So if these conditions where true we add the object to a Potential Targets Array which we then could use in our targeting system. The problem with this turned out to be the FieldOfView itself ! For example when we have a character that was bigger then our eye sight it would obscure our vision. Which of course is intended but also meant that when we checked of that character was in our FieldOfView we got irregular results as we could not see the objects front if we where behind him and vice versa.
The second iteration of the target system : Abandoning this tactic I went for a much simpler one where we now just shoot a RayCast line from the target to the source in our collision field. If the RayCast actually hits the target then obviously we can see him and add it to the potential target list. After this was done it was a simple matter of binding the Tab key to a script that cycled through all our potent targets in the array move a targeting ring underneath the selected target.
Β
GUI Element for the selected target : Now that we have a target selected it would be nice to reflect that not only by using a targeting ring but also in the GUI. I wanted to create the classical item where you see a ring containing the animation of Β the head of your target, so you can see its facial expression when tossing that fireball at him ! Next to that the defaults like name and health bar. The name and health bar where pretty straight forward and nothing special. It took a bit more to get the characters head in there though π After some research I found out that you could use a RenderTexture, which is a unity pro feature. This texture can display for example the image of a camera bound to it. So I set up a new dynamic camera that would attach itself right in front of the face of our selected character and send it’s feed to the render texture which is placed inside the GUI target ring. This worked as a charm but you would see everything behind the target as well. Setting the camera depth to a very small value made sure that everything behind the head turned into a solid color , which you could then make transparent. There you go, A live feed of your targets head in the GUI π
Β
The new spell :

Of course you cannot have a mage without the classic Magic Missle ! In stead of just creating a particle effect that zips in a beeline from caster to target I wanted it to be a bit more dynamic, chaotic and in the future make them more controlled. Now that we do have a targeting system we can select our target and prepare our missiles. The first step is getting a beeline from our caster to the target, get the distance between them and divide that by a reasonable amount so you get equal chunks. Then I wanted to deviate randomly some points off that path. Wes helped me with the 3d vertex math of placing the points randomly among the X and Z axis. After this was done I usedΒ iTween to give it the missle, the path and the final target. As each missile will calculate its own random path on instantiation you get a very nice chaotic effect when shooting for example a barrage of 5 magic missiles π
Β
Fixing some of the animations : Currently when you are walking around and start casting a fireball the casting animation would take over from walking and you’d slide forward until you are done casting and the walking animation takes over again. This really looks nasty. In stead of needing an other animation that makes the character walk and cast unity allows you to actually combine the two separate animations ! First you have to put the animations into layers and group those on mutual exclusiveness. For example idle, walk , run will be layer 0 and casting in layer 1. Then you detect if you are moving and want to cast. If this is the case you’ll tell the casting animation that it may only use the animations from the spine of on. This way the legs are being left alone. Now you can blend the two animations creating a walking casting character !
Β
Finally:
As I’m getting more and more to terms with unity and the scripting I wanted to clean up all of the scripts made before. Making sure to abide by the conventions of naming classes, variables and methods. Also the project’s hierarchy was becoming quite messy so we cleaned that up as well.
As usual you can find an updated progress of the current state here π
