Saturday, 5 February 2011

Test - Lure Mechanic

To begin this test I created a very simple environment of three corridors.


The player begins at the bottom left horizontal corridor. From there they are able to see a particle system which represents the Lure for this test. Below is an example of the players perspective at the beginning of the test as well as the particle system which represents the Lure.


I created a simple Javascript which activates an animation that is attached to the particle system. This script which I call triggerAnimation is attached to a invisible collider which is placed just before where the particle system can be scene in the image above. Here is an example of the triggerAnimation:


var myBox : Animation;

function OnTriggerEnter( other : Collider){

if(other.gameObject.name == "Player"){

myBox.Play();


}
}

Unity then runs the script above when the player walks into the invisible collider just before they reach the particle system, this then activates the animation attached to the particle system which animates it disappearing around the corridor.

This worked perfectly but I had hit a problem, the particle system was now sitting around the next corner waiting for the player and due to the lack of my scripting knowledge I was unable to write a script which would then animate the particle system disappearing around the next corner upon the player walking through a second collider.

To get by this problem I created a second script which would delete the particle system from the game once it was out of view from the player. That way I could have a second particle system waiting around the second corner with its own animation, corresponding collider and triggerAnimation script. To delete the first particle system I had to place a collider just before the corner of the first corridor so that when the player walks into this collider my script which I have called destroyLure is activated and deletes the first particle system from the game. Here is an example of the destroyLure script:


function OnTriggerEnter (other : Collider)
{

Destroy(gameObject.Find("lure"));
}

I continued the process above until I had three particle systems each with their own corresponding triggerAnimation and destroyLure scripts.


The image above shows the placement of the triggerAnimation scripts which are attached to three colliders (green boxes). The sun symbols represent the position of each particle system.


The image above shows the position of the destroyLure scripts which are attached to three colliders (green boxes).

Now that all the colliders, scripts and animations are in place when the player approaches the particle system it disappears around the corner encouraging the player to follow it. Just before the player walks around the corner of the corridor the first particle system is deleted from the game and only the second particle system can be seen. This gives an illusion that to the player that they are following only the one particle system around the corridors when in fact there are three placed in the scene.

No comments:

Post a Comment