2.5D Rotating Tower Effect For Platformers

In this tutorial we take a look at how to make a 2.5D Rotating Tower effect for a platformer game. This effect was made famous in games like ‘Mickey Mania’ and ‘Porky Pig’s Haunted Holiday’ and historically required some creative trickery to pull off. Now, using 3D objects alongside a 2D character it is really easy to create a similar effect quickly and easily.

Play test the level here.

Get the Unity Package here.

Pig sprite.

Seamless, tiling tree bark texture.

These are the scripts used in the level:

TreeTurn.cs

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

public class TreeTurn : MonoBehaviour
{
    public float speed = 1;

    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        transform.Rotate(0.0f, Input.GetAxis("Horizontal") * speed, 0.0f);
    }
}

 

Pig.cs

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

public class Pig : MonoBehaviour
{
    public float speed = 4;
    public float thrust = 100;
    public float maxJumpTime = 0.1f;
    public bool jumping;
    private float jumpTimer;
    private Vector3 startPos;
    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        startPos = transform.position;
    }

    void Update()
    {
        Camera.main.transform.position =
        new Vector3(Camera.main.transform.position.x, transform.position.y, Camera.main.transform.position.z);
        if (transform.position.y <= startPos.y - 15)
        {
            string thisScene = SceneManager.GetActiveScene().name;
            print(thisScene);
            SceneManager.LoadScene(thisScene);
        }
    }

    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.UpArrow) && jumpTimer <= maxJumpTime)
        {
            jumping = true;
            rb.AddForce(Vector2.up * thrust);
        }

        if (jumping)
        {
            jumpTimer += Time.deltaTime;
        }

        if (rb.velocity.y < -0.1f || jumpTimer >= maxJumpTime)
        {
            Physics.gravity = new Vector3(0, -25f, 0);
        }

        if (jumpTimer > 2f)
        {
            ResetJump();
        }
    }

    void OnCollisionEnter(Collision col)
    {
        if (col.collider.gameObject.tag == "Floor")
        {
            print("Floor");
            ResetJump();
        }
    }

    void ResetJump()
    {
        Physics.gravity = new Vector3(0, -9.8f, 0);
        jumping = false;
        jumpTimer = 0;
    }
}

Seamless, tiling tree bark texture:
CC-BY-SA 3.0 : Bart K

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *