Select Page

GMD Class 04 nonDivi

Outline:

  • Animation Sprite Sheet
  • Tilemaps
  • Platformer: Enemies (movement, death, attack)
  • Assignment 02

Animation Sprite Sheet

Sprite Sheet:

A sprite is a game term to mean a simple graphic. A sprite sheet is a collection of sprites, usually including animation.

Platformer Sprites:

For your current game and assignment, you should complete the following:

Player Animations (for platformer)
  • Idle
    The default position of the character
    Single image or animation

  • Walk, Run or both
    Basic locomotion
    Animation

  • Jump, Fall, or both
    Pose of the character in air
    Single image
  • Injury, Death, or both
    Character being damaged
    Single image
Player Animations (for Cecil Smash)
  • Light Attack
    Quick weak hit like a jab
    Single image
  • Medium Attack
    Moderate speed, moderate damage attack like a kick
    Short, two frame animation


  • Heavy Attack, Range Attack, or both
    Slow strong attack that can be a big hit or something at a far distance
    Short, three frame animation
  • Block
    Character defending themself
    Single image
  • Special
    Whatever special ability they have when charged up
    Nothing elaborate
Enemy Animations
  • Locomotion
    Patrolling
    Single image or animation
Walk Cycle Keys
01
04
06
08
12

contact
low
passing
high
contact
Run Cycle Keys
01
03
04
06
08

contact
low
passing
high
contact
Player Sprite Sheet

Platform Sprites

Tilemaps

Tilemap:

Tilemaps are Unity's built-in grid-based system for developing 2D environments.

  1. Create a sprite sheet of the environment in discreet cells.
  2. Import with the proper settings and slice using cell size or number.
  3. Create a Tilemap, GameObject>2D Object>Tilemap.
  4. A Grid object with a Tilemap child is created but you may add as many Tilemap layers as you desire.
  5. Open the Tile Pallete, Window>2D>Tile Pallete.
  6. Drag your sprite sheet into the Tile Pallete.
  7. Use the various tools to "paint" your level.
  8. Add the Tilemap Collider 2D and check on Used by Composite.
  9. Add the Composite Collider 2D.
  10. A Rigidybody 2D is automatically created. Change the Body Type from Dynamic to Static.

Platformer: Enemies (movement, death, attack)

Let's add some simple enemies in the game.

Here is what we are making

You may download the Unity project here.

Assets

Environment
Background
The imagery behind the player character, purely aesthetic
Midground
The imagery that the player character can actually contact, ground, platforms, walls, etc.
Foreground
The imagery in front of the player character, purely aesthetic
Characters
Player
The protagonist controlled by the player
Enemy
The antagonists that block/kill the player character
Other(pickups, UI, etc.)
Score Pickup
Collectables that you gather for a total score
Health/Life Pickup
Restores player health


we will use stand-in sprites to start off with but you will eventually make your own graphics.

Scripts

Previous Scripts
PlayerControllerScript
Moves the player based on user input
DeathBoxScript
Broad script that will "kill" the player.
GameControllerScript
Holds code that controls aspects of the game such as loading levels, controlling GUI, etc.
PlayerStatsScript
Generally used to hold information regarding the player character like score, player health, etc.
New Scripts
EnemyControllerScript
Controls the enemy movement and attack.
Updated Scripts
GroundCheckScript
Checks that the player is on the ground but will now also detect whether the player jumps on enemy.

GameControllerScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameControllerScript : MonoBehaviour
{
    public void Victory()
    {
        Debug.Log("You Won!");
    }
}
Previous Scripts

PlayerControllerScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControllerScript : MonoBehaviour
{
    [SerializeField] float playerSpeed;
    [SerializeField] float playerJumpStrength;

    public bool ground;

    private Rigidbody2D playerRB2D;

    void Start()
    {
        playerRB2D = GetComponent();
    }

    void Update()
    {
        playerRB2D.velocity = new Vector2((Input.GetAxis("Horizontal") * playerSpeed), playerRB2D.velocity.y);

        if(Input.GetAxis("Jump") > 0 && ground)
        {
            playerRB2D.AddForce(transform.up * playerJumpStrength);
        }

        if(Input.GetAxis("Horizontal") > 0)
        {
            GetComponentInChildren().flipX = false;
        }
        else if(Input.GetAxis("Horizontal") < 0)
        {
            GetComponentInChildren().flipX = true;
        }
    }
}

DeathBoxScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeathBoxScript : MonoBehaviour
{

    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.tag == "Player")
        {
            col.gameObject.GetComponent().Lives(-1);
        }
    }
}

PlayerStatsScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerStatsScript : MonoBehaviour
{
    public Vector2 playerStartPosition;
    Text lifeText;

    public int playerLives = 3;

    void Start()
    {
        playerStartPosition = transform.position;
        lifeText = GameObject.Find("LifeText").GetComponent();
    }

    public void Lives(int life)
    {
        if(life == -1)
        {
            transform.position = playerStartPosition;
        }

        playerLives += life;
        lifeText.text = "Lives: " + playerLives;
    }
}

PlayerPickupScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPickupScript : MonoBehaviour
{

    public GameControllerScript gameControllerScript;
    public PlayerStatsScript playerStatsScript;

    void Start()
    {
        gameControllerScript = GameObject.Find("GameController").GetComponent();
        playerStatsScript = GetComponentInParent();
    }


    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.tag == "Finish")
        {
            gameControllerScript.Victory();
        }
        else if(col.tag == "ScoreItem")
        {

        }
        else if(col.tag == "Life")
        {
            playerStatsScript.Lives(1);
            Destroy(col.gameObject);
        }
    }
}
New Scripts

EnemyControllerScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyControllerScript : MonoBehaviour
{

    public float enemySpeed;
    private int enemyDirection = 1;

    private Vector2 enemyScale;
    private Rigidbody2D enemyRB2D;

    void Start()
    {
        enemyScale = transform.localScale;
        enemyRB2D = GetComponent();
    }

    void Update()
    {
        Move();
    }

    void Move()
    {
        enemyRB2D.velocity = new Vector2((enemySpeed * enemyDirection), transform.position.y);
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.tag == "EnemyBlock")
        {
            enemyDirection *= -1;
            transform.localScale = new Vector2((enemyScale.x * enemyDirection), enemyScale.y);
        }
        if(col.tag == "Player")
        {
            col.gameObject.GetComponent().Lives(-1);
        }
    }
}
Updated Scripts

GroundCheckScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GroundCheckScript : MonoBehaviour
{
    public PlayerControllerScript playerControllerScript;

    void Start()
    {
        playerControllerScript = GetComponentInParent();
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.tag == "Ground")
        {
            playerControllerScript.ground = true;
        }
        if(col.tag == "Enemy")
        {
            Destroy(col.gameObject);
        }
    }

    void OnTriggerStay2D(Collider2D col)
    {
        if(col.tag == "Ground")
        {
            playerControllerScript.ground = true;
        }
    }

    void OnTriggerExit2D(Collider2D col)
    {
        if(col.tag == "Ground")
        {
            playerControllerScript.ground = false;
        }
    }
}

Assignment 02

Character Animation

The second assignment in the platformer game is to develop the artwork and animation for the characters of your game. This means you will produce a sprite sheet for the player character that contains all the frames of its movement. You may use any software you would like to develop the sprite sheet but the final output should be a large png file with all frames contained within it in an orderly manner.

You will be graded on the following:
  • Player Walk/Run Animation:
    • Final walk or run cycle has all necessary poses keyed. Animation is full and contains strong canon.
  • Player Idle & Jump Animation:
    • The motion the player makes while doing nothing as well as the frame/s for jump and fall.
  • Player Special (attack, Block, Damage, etc.):
    • Any other animations necessary for your game. This could be different depending on what novel features you add later.
  • Sprite Creation:
    • The animation frames should be placed in an even grid to make application in Unity easier.
Resources:
  • You can find the rubric under the Assignments content folder in Blackboard.

Platformer Tutorial