Messing Around - Making isometric RPG mechanics in Unity

in #gaming6 years ago (edited)


I've actually gone and done it! I made a post about this on the Unity forums and there was some helpful responses but I also found an article that went into detail about how to do it a bit but once you break it down like with most things it actually became quite easy to implement. The maths behind it and how it all works is quite complicated and I'm still figuring it out but I have the general idea now.

https://connect.unity.com/p/articles-what-i-learned-from-trying-to-make-an-isometric-game-in-unity

https://forum.unity.com/threads/how-did-the-obsidian-developers-do-the-art-for-tyranny-and-pillars-of-eternity.524984/#post-3450500

Here are the two places I gathered information on this, after this it was just trial and error, you can also grab my project in the Unity thread and see it all working for yourself for free! Use the WASD keys to move the camera and the left mouse button to move the little blue capsule.

There isn't even actually that much coding required to do this isometric technique but the way you have to set everything up is very weird. The first step is to create a plane, yes, absolutely nothing fancy, I suppose you could do more advanced stuff with a terrain object but I haven't bothered because I just wanted to get it to work and it looks like the games developers who use this technique don't bother either. I then flipped it around to turn it into the shape of a diamond.

Now here's where things get weird, to get the actual look right, I then got my camera, rotated it to 45 degrees, makes sense right? Because the artwork is on a 45 degree perspective that's what isometric art is like. I then had to switch the camera to orthographic and in the 3D viewport you simply import your sprites as I have done, drag them in and it's done! That's literally all there is to it, you just need to make sure that the sprites are horizontal as that's to do with how the orthographic camera works. As you can see in the actual project there's stuff I would tweak with the art but that should all come later I think.

How did I get the movement to work? Well, for the camera as I thought, all I needed to do was to set up an empty gameobject and attach the camera. Now under normal co-ordinates this would just work out of the box when you put the movement code in, but because of the way isometric RPGs work with their tile grids and so on the co-odrinates system is different.

This leads me to something I literally just had to learn yesterday, they're called Cartesian co-ordinates, I'm still looking at it all and trying to understand it but this little bit of maths if you want to get the true isometric experience going with you game is what you need to learn to get not only the camera movement right but if you want your characters moving on a grid like in the original Fallout games these are the co-ordinates for you.

https://en.wikipedia.org/wiki/Cartesian_coordinate_system - Here's the theory

Here's the implementation, I did it just by trial and error really but it does make sense and I'm sure anyone more mathematically inclined can check this out and do it for themselves.


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

public class RPGMoveCamera : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {

        if ( Input.GetKey ( KeyCode.W ) ) 

        {
            gameObject.transform.Translate ( -2, 0 , -2);
        }

        if ( Input.GetKey ( KeyCode.S ) )

        {
            gameObject.transform.Translate ( 2, 0 , 2);
        }

        if ( Input.GetKey ( KeyCode.A ) )

        {
            gameObject.transform.Translate ( 2, 0 , -2);
        }

        if ( Input.GetKey ( KeyCode.D ) )

        {
            gameObject.transform.Translate ( -2, 0 , 2);
        }

        
    }
}

So with that done we move to the final bit and that is the actual movement of the characters, now I'm not a purist as there are things about traditional RPGs that have annoyed me. Some of which have been the way the characters move and so on themselves so I quite like just having a very nice, smooth movement, taking advantage of the benefits that modern gaming provides.

With that in mind, I needed to have a look at my sprites, I put colliders on them that roughly matched where the blue capsule would be able to go. Something I forgot simply because I haven't needed to use Unity's navmesh feature for awhile is that you need to put in navmesh obstacles onto these objects as well so that Unity can understand the blue capsule should avoid.

After this, simply click on the plane, bake the navmesh and then that should be that, the setup is done for the environment. Now, as for the moving the capsule this is more simple than I thought as well, I created a NavMeshAgent component and then got this script from the official unity documentation. They have helpfully provided people a built in click to move feature which does all you need for these kind of isometric games. Simple attach the script to the capsule, drag the NavMeshAgent component to the public slot created by the script and again, I was done, just like that.


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

public class MoveAgentOnClick : MonoBehaviour {

    
    public NavMeshAgent agent;

    // Use this for initialization
    void Start () {

        agent = GetComponent<NavMeshAgent>();
        
    }
    
    // Update is called once per frame
    void FixedUpdate () {

        if ( Input.GetMouseButtonDown ( 0 ) )

        {
            RaycastHit hit;

            if ( Physics.Raycast ( Camera.main.ScreenPointToRay ( Input.mousePosition ) , out hit, 1000 ) ) 

            {
                agent.destination = hit.point;
            }

        }
    }
}

It's interesting that there aren't very many detailed tutorials on this subject but perhaps my writeup will interest people especially those who just want to know how isometric RPGs work or want to have a go at making one themselves.

The next obvious step now after this would be to fix the movement of the player capsule, do some tweaking and just go absolutely nuts writing up the combat rules and doing some inventory coding. I'm sticking to shooters for now though and have some ideas generally at the moment on what to do, in order to make a really nice RPG it will take a lot of 2D art skill and writing skill something I'm not completely ready for yet.

Sort:  

hi there!!!! that it is awesome! i do cad cam too so i love it!!!
good luck!!!
have a great day!!!

What's fascinating about isometric RPGs isn't just the art side of it which is almost all 2D depending on the game but you can have a huge amount of detail in your games without wrecking peoples' PCs like with purely 3D games, really enjoyed checking this stuff out for myself.

Should point out this is 2D mixed with 3D so it's not exactly like CAD, this is to do with gaming.

Congratulations @lethn1! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published

Click on any badge to view your own Board of Honor on SteemitBoard.

To support your work, I also upvoted your post!
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Do not miss the last announcement from @steemitboard!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63501.83
ETH 2650.23
USDT 1.00
SBD 2.81