Thursday 3 May 2012

Scripting animations, pickups...

Having never scripted animations within Unity I used the Lerpz tutorial found here. My initial script for the animations showed a sliding effect when moving. As this script would not do I used the ThirdPersonController script included in the Lerpz tutorial. This allowed the animations to move smoothly based on the player's input.


This video demonstrates the Third Person Controller script in action, with the animations blending smoothly. The attack animation is triggered separately when the player clicks the mouse heres the script for that:


In this script it shows the wrapmode of the animation to be on loop for a continuous animation. It also detects the Fire1 input which is the default left mouse click control name. GetButtonDown means once the left mouse is clicked the animation will play once, if it were GetButton it would continue looping while the mouse was held down. I adapted it to be a one click hit for our game.






Third Person Controller
This has slots for the animations that can be selected in the Unity. The animations are stored in the player prefab, where the animation is split up into the run idle and attack for Gutsy.

Here the Gutsy animation keyframes chosen, broken up and named correctly.


 In the collisions script I added a point system which is controlled by the points manager script. You can specify in the Inspector window of Unity how many points to take when colliding with the coins/health.


This shows the animations that are attached to the Gutsy model separated into 3 elements. I have deselected the play automatically button as I want the animations to be triggered by the script only. 

The collision script:

Here is the spawn system used for the coins. I have created 4 Empty Objects within Unity which are invisible objects used as a reference points. The script spawns the object selected in the chosen spawns. This was adapted from the enemy spawn hence the variable 'amount of enemies'. This section allows you to change the amount of objects spawned, when they start spawning and how often they will spawn after the initial spawn.



No comments:

Post a Comment