-
-
Notifications
You must be signed in to change notification settings - Fork 52
Home
- Why not use a tilemap?
- Where can I find the grid reference for stage 1-1?
- Enemies do not face the direction they are moving
- The camera is not transitioning underground after entering a pipe
Using a tilemap for level design does make the process of constructing the levels easier; however, it makes other aspects of the game more difficult to implement. I did use a tilemap for my first iteration of the game but as soon as I started scripting everything in the game, it become clear that a tilemap was only making the game much harder to make.
Frankly, Unity's tilemap system isn't very good if you want to have interactive, scriptable objects placed on a tilemap. For example, some of the blocks are animated when Mario hits them. There's no straightforward way to do this without jumping through some loopholes. I'm not saying it's not possible, but it becomes a lot harder and ultimately not worth it, in my opinion.
You cannot even attach a script to an object placed on the tilemap unless you install a tilemap "extras" package. I used this package in my Pacman tutorial, but I wanted to keep this tutorial as simple as possible, so I decided not to use a tilemap.
The reference image can be found here: https://github.com/zigurous/unity-super-mario-tutorial/blob/main/References/1-1%20Grid.png
This was an oversight on my part since most of the enemies are symmetrical so you don't notice it, but this is not the case for Koopa. Only a couple lines of code are needed in the EntityMovement.cs
script to fix the problem for all entities.
Add the following lines of code to the bottom of the FixedUpdate
function:
private void FixedUpdate()
{
//...
if (direction.x > 0f) {
transform.localEulerAngles = new Vector3(0f, 180f, 0f);
} else if (direction.x < 0f) {
transform.localEulerAngles = Vector3.zero;
}
}
The camera transitions underground when entering a pipe only if the y-position of the connection is below zero. If you believe this to be the case, but the camera is still not transitioning underground, it's likely because your entire stage is offset - the local position might still be zero or less but the world position is not. Check that the parent "Stage" game object has its position reset to 0,0,0.
Instead of assuming the underground starts at a y-position of zero or below, we can add a variable to customize this per each level. Add the following variable to your SideScrolling.cs
script:
public float undergroundThreshold = 0f;
Then, in the Pipe.cs
script replace this line of code:
Camera.main.GetComponent<SideScrolling>().SetUnderground(connection.position.y < 0f);
with this instead:
var sideSrolling = Camera.main.GetComponent<SideScrolling>();
sideSrolling.SetUnderground(connection.position.y < sideSrolling.undergroundThreshold);
This code uses that new variable to determine if the camera should transition underground. You can customize the value of this variable on your camera game object as needed.