Gamespace: Moving End Platform (Panel Animation)

Once I had got the platform to move back and forward, I decided that I wanted the panel to lift up depending on whether the player was close to the platform otherwise the panel would stay downwards.


Panel staying down

This is the inspector for the moving end platform.
The 'Panel Open for Player' and 'Panel Closed for Player' scripts are attached to this object.
A sphere collider has also been added so that when the player collides with the collider this triggers the panel to lift.


Moving End Platform Inspector


Sphere collider where the panel is lifted

The 'PanelClosedForPlayer' plays the closed animation when the player has not collided with the collider.

If the 'IsOpen' parameter on the animator is false then the panel will close otherwise the panel will be open.


Panel Closed For Player Script


The 'PanelOpenForPlayer' script uses the 'OnTriggerEnter' function which is triggered when the player has collided with the panel. 

The animator attached to the object has been recieved by the script.
The open door animation will play lifting the panel, as it has been triggered by the collider and the 'IsOpen' parameter on the animator is set to true.

When the player is out of range of the collider on the panel, the 'OnTriggerExit' function will play activating the close door animation and the IsOpen parameter on the animator is set to false. 



Panel Open For Player Script


The animations created for 'Up' and 'Down' had been recorded and saved as animation assets using the record button on the animation panel. By skipping to one second and moving my panel either upwards or downwards created a motion path creating my open/close animations.


Animation panel where I recorded my panel animations

The Loop Time has been unchecked so that they do not repeatedly play.


Inspector for Down Animation

Transitions were created between the 'Up' and 'Down' animations. 
When the Boolean parameter 'IsOpen' is unchecked the panel is constantly down whereas if it is checked it is constantly open. I have left the checkbox unchecked so that the panel is constantly down unless triggered by the scripts (meaning that the player has collided with the collider).
The boolean value and transitions work by telling the animator that when one animation is played continue playing that animation until a condition states that the other animation should be played. Both animations never play at the same time, due to the parameter being of a boolean type.




Animator Panel

When clicking the down animation block in the animator, the inspector appears for this animation. 
I added the condition through the animator that when the condition for the 'IsOpen' parameter is true (defined in the script) then the down animation stops playing and the Open animation is played.



Down Animator Inspector

When clicking the Up animation block in the animator, the inspector appears for this animation. 
I added the condition through the animator that when the condition for the 'IsOpen' parameter is false (defined in the script) then the up animation stops playing and the Down animation is played.



Up Animator Inspector

Comments

Popular posts from this blog

Unity Project 4: Ball platformer game

[Research] Traditional Poster Design (4CTA1214)