Adventure Calls!
Unity Action RPG
A Zelda-like slice: 8-way movement with animation states, sword swings with hitboxes, enemy AI, hearts, pickups and scene-to-scene world flow. The biggest Unity build in the series.
A Zelda-like slice: 8-way movement with animation states, sword swings with hitboxes, enemy AI, hearts, pickups and scene-to-scene world flow. The biggest Unity build in the series.
Build smooth 8-way movement through the physics system.
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
public float speed = 5f;
Rigidbody2D rb;
Vector2 input;
void Awake() { rb = GetComponent<Rigidbody2D>(); }
void Update()
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
input = input.normalized;
}
void FixedUpdate()
{
rb.linearVelocity = input * speed;
}
}
Hook movement into Unity’s animation state machine.
Animator anim;
void Update()
{
// ... input reading ...
anim.SetFloat("Speed", input.magnitude);
if (input.x != 0 || input.y != 0)
{
anim.SetFloat("DirX", input.x);
anim.SetFloat("DirY", input.y);
}
}
Implement melee attacks with proper hitboxes.
using UnityEngine;
using System.Collections;
public class SwordAttack : MonoBehaviour
{
public GameObject hitbox;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
StartCoroutine(Swing());
}
IEnumerator Swing()
{
hitbox.SetActive(true);
yield return new WaitForSeconds(0.15f);
hitbox.SetActive(false);
}
}
IEnumerator Swing()
{
hitbox.SetActive();
yield return new (0.15f);
hitbox.SetActive();
}
Build enemies that chase, hurt, and get knocked flying.
using UnityEngine;
public class Enemy : MonoBehaviour
{
public int hp = 3;
public float speed = 2.2f, aggroRange = 4f;
Transform player;
Rigidbody2D rb;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void FixedUpdate()
{
float dist = Vector2.Distance(transform.position, player.position);
if (dist < aggroRange)
rb.linearVelocity = (player.position - transform.position)
.normalized * speed;
else
rb.linearVelocity = Vector2.zero;
}
public void TakeDamage(int amount, Vector2 fromDirection)
{
hp -= amount;
rb.AddForce(fromDirection * 8f, ForceMode2D.Impulse);
if (hp <= 0) Destroy(gameObject);
}
}
Complete the combat loop with player health done properly.
public IEnumerator Hurt(int dmg, Vector2 knockDir)
{
if (invincible) yield break;
hp -= dmg;
UpdateHeartsUI();
if (hp <= 0) { GameOver(); yield break; }
invincible = true;
for (int i = 0; i < 6; i++) // flash 6 times
{
sprite.enabled = !sprite.enabled;
yield return new WaitForSeconds(0.12f);
}
sprite.enabled = true;
invincible = false;
}
Connect scenes into a world and ship the vertical slice.
using UnityEngine;
using UnityEngine.SceneManagement;
public class Door : MonoBehaviour
{
public string targetScene;
public string spawnId;
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
SpawnManager.nextSpawnId = spawnId;
SceneManager.LoadScene(targetScene);
}
}
}
if (other.CompareTag())
{
SpawnManager.nextSpawnId = ;
SceneManager.(targetScene);
}
Keep the Unity cheatsheet handy
MonoBehaviour, physics and UI in one place - use it beside this workshop.
Design your RPG sprites and icons!
Use Pixel Studio to create your hero, enemies, and UI icons - then import them into your Unity RPG.
Vector2 movement = new Vector2(moveX, 0);void Update() {}float moveX = Input.GetAxis("Horizontal");rb.velocity = movement * speed;