[Project Week 12] Spell exit points

Spell cast from staff

This week I will be changing my attack down animation and also changing the spell casting a little so that the spell spawns from the players staff instead off from its body, so that it looks like the wizard character is shooting attacks from its staff which is how it should be right now. The problem right now with the attack down animation is that the character moves a little bit to the right after casting which looks bad visually, so I need to fix that this week.

Fixing attack down animation

The way to fix the animation bug is simple, all I had to do was select all of the attack animations in the Unity editor like so:



And then set a custom pivot point to 0.54, after doing so the player doesn't move to the right anymore after attacking:



Shooting from the players staff

To do this I need to create 'exit points' and what this basically means is I need to create spawn points on the players animation akin to the position of the staff, so for example if the player is looking down the exit point would differ to when the player is looking right because the position of the staff would be different. So for this reason I will be creating 4 exit points, one for down, left right and up:



Placing the exit points is simple enough, I simple dragged each of the exit points onto the staff in all the different animation positions on the Unity canvas:



Script

Next thing to do was to write a script, first I created a new transform array called Exit Points which will are the points for exiting my spells:



This allows me to create 4 elements in the unity editor for each exit point:



Then I made a variable called exitIndex which will assure my exit points will be cast when facing the right direction:



Then I created all the exitIndexes for each key press so for W it will use the up exit point and for S it will use the down exit point, remember that the numbers are relevant to the exit point elements in the Unity editor, so 2 equals down exit point, D equals 1 etc:



Here is what the attack animation looks like now in my game, as you can see the attack comes from the players staff no matter the position. However, when the player is attacking while not facing the enemy the spells still attract towards it, this should not happen so I plan on adding a line of site to my attacks in the future to prevent this:




Comments