Yesterday we got the player jumping and limiting it a bit, but today we’ll create a more solid approach to limiting the players jumps by creating a cooldown system.
As with any cooldown system, we’re going to need a permission boolean to give the OK when it’s safe to commit to an action again.
Next in the jump function, we’ll set _resetJumpNeeded to true
Last time we programmed our player to jump using a character controller. This time, we’ll be using the Rigidbody2D component. We’ll need to check for the player to be grounded, but let’s start simple. Let’s get the player jumping.
After doing a bit of preliminary research, it seemed AddForce was the way to go, AddForce also has various modes: Acceleration, Force, Impulse, and VelocityChange. Impulse seemed to make the most sense, so let’s see if I chose correctly:
Today we write a script to get our player to move around but not like before using transform.translate, we’re going to be accessing the players rigidbody and manipulate that.
After creating a Player script, we create a handle for the rigidbody:
Next we want to figure out how to move the players rigidbody so we check out Unitys page, we want to affect its velocity and rigidbody has a velocity method so let’s check that out
With all of the various player states sliced and prepared, we’re ready to create an actual Player object!
First, we’ll grab the first player frame and drag it into the scene.
We can’t see the player sprite because the environment is set to various layer orders from 0 to 30, we’ll put our player sprite on layer order 50 so it appears above everything else.
Today was an easy challenge, we were given the task of setting up the various player animation states. A sprite sheet was provided for each one, as an example I’ll share the process for the idle state.
First the idle sprite tilesheet is selected, and then type is changed from default to “Sprite 2D and UI”.
Currently in our project, we’re given a level with an orthographic camera. The level is beautiful! Kudos to the artist who designed it. One thing though is if you move the camera back and forth, it’s kind of flat.
The level is designed with various layers of tilemaps like the one we created in the past few days. One thing we can do to give it more depth is to change the camera to perspective.
The nice thing about linux is when it comes to programming, it has pretty much everything out of the box.
Case in point, I’m going to open a terminal with Ctrl-Alt-T and type “java -version” to see if it’s installed.
And it appears I do have the latest version! Huzzah! Moving right along to Unity! Let’s go into build settings and switch to Android.
Currently the level is only a set of tilemaps, if we wanted to have a player object interact with it, we’de need a collider on the ground for the player to stand on.
For that to happen, we only need to attach a TileMapCollider2D component to the appropriate tilemap, in this case, the ground tiles:
The next part of the class talked about Prefab brushes, which, unfortunately, seem to be a deprecated item but are now replaced with the GameObject brush. A huge thank you to James West for his article on this latest update.
First of all, you can no longer create a Prefab brush as before, you’ll have to go into the Tile palette menu and select the GameObject brush instead
Before continuing on, I figured I’d share what the course is having us do and that’s slice a diamond sprite up in 32x32 cell sizes which I’m assuming the frames will be…
In the past, if you wanted to have animated Tilemaps in Unity, you had to go into Unitys github and manually download ‘Tilemap Extras’ and install it. Now you can install it directly from the package manager albeit with a few extra steps:
First you need to go to Edit/Project Settings/PackageManager and tick “Enable Preview Packages”
You’ll get a warning about how these are brand new options and that Unity won’t be responsible for any PCs catching on fire, giving up your first born to the elder gods blah blah, yada yada, click “I understand”.
cartoonist, game artist, and wanabe gamedev.