Lynda.com: Become a Unity 2D Developer (Day 11..Sort of)
UNITY 2D LEVEL DESIGN (...continued part IV)
Unfortunately, I had to take a huge departure from learning Unity. Let's just say that I'm also studying Cisco stuff. Needless to say, I figured it was time to finish what I had started.
Switches
Create Switches
This chapter was similar to other animation tutorials, specifically in the setup process. First, I had to create a switch object by utilizing the three images of the switch, which are the three states of the switch, specifically "Down, Up, and Idle".
Afterwards, it was a matter of setting up the animations and then sequencing them. I created three animations for the switch: SwitchUpAnimation, SwitchDownAnaimtion, and SwitchIdleAnimation. From there, the AnimState was configured according to the sequence of the animation.
Switch Collision Trigger
Creating the switch now leads to implementing code. First, I created a new C# script and then proceeded to create new functions for each AnimState. **It is important to note that MonoDevelop is now being utilized within VisualStudioCode, which is why the GUI is completely different when compared to the prior blog posts.**
Next, I then applied a Box Collider 2D onto the switch and set it to trigger.
Of course, before I move forward, I had to test it to ensure that the animations work with gamer interaction. Luckily, it was a resounding success.
Use the Switch
This section focuses on adding logic from the switch to the floor. Ideally, when the Astronaut steps on the switch, it should open the door. In order to accomplish this, I had to use the following C# code and then assign them to the Door and Switch objects accordingly.
Create Gizmos
Creating Gizmos helps visualize the correlation between various objects and functions. At this time, there is no correlation between the switch on the floor and the door. In order to create the initial correlation, I had to implement some C#.
From here it was a matter of testing the script. Within the Switch, there is a new toggle for Sticky. When "ticked or unticked", there is a visual indicator of a green or red line from the switch and the door.
Create a Push Block
In order to create a bit more difficulty to the game play, it would be best to incorporate a push block element to the door trigger scenario. Ultimately, I will need to create a block that the player will be able to place on top of the trigger, thus allowing the player to fly through the doorway successfully.
First, I selected all of the push block artwork and placed them onto the stage as a new animation object. Next, I modified animation timeline and placed the last four frames on the 2 second mark. Visually, this shimmering effect will act as an indicator that the block is different when compared to the rest of the blocks within the stage.
Next, it is time to see this block in action. I had to replace the trigger to the exact location in which the player would land. In addition, the block has been modified to include a Box Collider 2D and Rigidbody 2D at default settings.
Now, when the player lands on top of the trigger, it will open the door but close immediately as soon as the player steps off the trigger. Thus forcing the player to explore and try other options.
There is a bit of an unwated problem with the mechanics of the block. Noticeably, when the astronaut flies into the top part of the block, the block begins to tilt. In order to resolve this tilting mechanic, the Rigidbody 2D settings have been modified to the following:
Mass: 3
Linear Drag: 1
Freeze Rotation Z
Now, when the astronaut flies into the block, it takes more momentum to move the block and it no longer tilts.
Unfortunately, I had to take a huge departure from learning Unity. Let's just say that I'm also studying Cisco stuff. Needless to say, I figured it was time to finish what I had started.
Switches
Create Switches
This chapter was similar to other animation tutorials, specifically in the setup process. First, I had to create a switch object by utilizing the three images of the switch, which are the three states of the switch, specifically "Down, Up, and Idle".
Afterwards, it was a matter of setting up the animations and then sequencing them. I created three animations for the switch: SwitchUpAnimation, SwitchDownAnaimtion, and SwitchIdleAnimation. From there, the AnimState was configured according to the sequence of the animation.
Switch Collision Trigger
Creating the switch now leads to implementing code. First, I created a new C# script and then proceeded to create new functions for each AnimState. **It is important to note that MonoDevelop is now being utilized within VisualStudioCode, which is why the GUI is completely different when compared to the prior blog posts.**
Next, I then applied a Box Collider 2D onto the switch and set it to trigger.
Of course, before I move forward, I had to test it to ensure that the animations work with gamer interaction. Luckily, it was a resounding success.
Use the Switch
This section focuses on adding logic from the switch to the floor. Ideally, when the Astronaut steps on the switch, it should open the door. In order to accomplish this, I had to use the following C# code and then assign them to the Door and Switch objects accordingly.
Create Gizmos
Creating Gizmos helps visualize the correlation between various objects and functions. At this time, there is no correlation between the switch on the floor and the door. In order to create the initial correlation, I had to implement some C#.
From here it was a matter of testing the script. Within the Switch, there is a new toggle for Sticky. When "ticked or unticked", there is a visual indicator of a green or red line from the switch and the door.
Create a Push Block
In order to create a bit more difficulty to the game play, it would be best to incorporate a push block element to the door trigger scenario. Ultimately, I will need to create a block that the player will be able to place on top of the trigger, thus allowing the player to fly through the doorway successfully.
First, I selected all of the push block artwork and placed them onto the stage as a new animation object. Next, I modified animation timeline and placed the last four frames on the 2 second mark. Visually, this shimmering effect will act as an indicator that the block is different when compared to the rest of the blocks within the stage.
Next, it is time to see this block in action. I had to replace the trigger to the exact location in which the player would land. In addition, the block has been modified to include a Box Collider 2D and Rigidbody 2D at default settings.
Now, when the player lands on top of the trigger, it will open the door but close immediately as soon as the player steps off the trigger. Thus forcing the player to explore and try other options.
There is a bit of an unwated problem with the mechanics of the block. Noticeably, when the astronaut flies into the top part of the block, the block begins to tilt. In order to resolve this tilting mechanic, the Rigidbody 2D settings have been modified to the following:
Mass: 3
Linear Drag: 1
Freeze Rotation Z
Now, when the astronaut flies into the block, it takes more momentum to move the block and it no longer tilts.















Comments
Post a Comment