NaughtScape [01] - First came the land to walk on.

in #programming6 years ago (edited)

What is NaughtScape ?

NaughtScape is the working name for a game I decided to try and make using C# and the Unity engine. I am basing the game off of one of my favourite games, Old School RuneScape (OSRS). My overall goal for this game is to have a few things implemented, namely:

  • A small arena to be the game world
  • A couple NPC enemies
  • A few weapons and armours
  • The 3 attack types (Melee/Range/Magic)
  • The ability to fight the NPCs

Now I know it sounds like quite a bit for one person to do ... and it is. It doesn't help in that trying to emulate how OSRS is styled and does things I will end up making more work for myself than might be necessary.

My plan is to start out with creating the game world, and then move onto the player character and movement. I will be trying to keep the visual style as close to OSRS as much as I'll be able to.

First steps

I started out with needing a ground plane. In OSRS the ground is divided up into tiles, and the movement is based on that instead of a continuous ground plane. This means I can't just spawn in a big flat plane, throw on a colour, and call it a day. I had to figure out a way to generate a ground plane made up of individual tiles. To do this I followed a wonderful tutorial by the Quill18Creates YouTube channel. This was a great introduction for me into the subject of generating tile maps through code, and helped me understand vertices and triangles in relation to rendering graphics a little better.

In Quill's videos he walks through building up the mesh of tiles through a couple of for loops that count to a public size value for the width and height of the tile map. I went over the map twice, the first run was to create the vertices:

For Loop Tiles.PNG

When I set each vertex I add a random fluctuation of the y value to create bumps and add texture.

The second time through was to create the triangles:

For Loop Triangles.PNG

Then I create the mesh and assign the values I set in the previous loops:

Set Mesh.PNG

Once the ground mesh exists, and as separate tiles to boot, I can call the BuildTexture() function to set up and attach some textures from my texture map. The BuildTexture() function stores a reference to the tile size, a holder for the Texture2D that will be applied to the tile, and a Color[][] that holds the individual textures chopped from the texture map provided. I then loop through up to the x and z sizes of the ground plane, and for each I randomly grab one of the 4 textures and apply it to the tile.

BuildTexture.PNG

After this all that's left is to apply the texture and add it to the MeshRenderer's shared materials.

Final product

First Tile Map.PNG

Rendered tile map with randomized tile textures from the texture map.

The Player

Now, I didn't want to start doing any modelling just yet but I did want to test some basic player functions like movement. To do this I created a Capsule object (Player Model) and plopped it in the scene. I set the transform of the player model to have a y value of 1. This will allow the capsule to always sit above the ground.

NOTE: I created an empty GameObject (PlayerGO) and placed the player model inside of that. I then set the PlayerGO's transform to (0, 0, 0). Now I can adjust the Player Model's transform without it effecting any movement code in the back end.

For the movement I wanted to copy the movement controls from _OSRS _exactly. This means a mouse based system where the different clicks mean:

  • Left-click - Will make the Player walk/run to the target tile
  • Right-click - will open a secondary options menu (which I will look into implementing later)
  • Middle-Mouse - Will rotate the camera around the player model. (While held)

I implemented a quick and dirty movement system for the time being, what ever tile is left-clicked on the player teleports directly to. I will eventually add a modified A* path-finding system, but I need to get the world generation finished first.

Now that I have a ground plane of tiles is generating and player movement is (sort of) figured out, I wanted to get the camera movement working. The intended goal for camera movement was to have the view centered on the player model at all times, but allow for the camera to be rotated around the player model and allow for the camera to be zoomed.
After much searching and a few tutorial implementations that just didn't work, I was able to make the camera rotation work ! I went through a few tutorials for orbiting a camera around an object and a couple about 3rd person camera controls before I came across this tutorial on the Star Space Era YouTube channel. The implementation for having a mouse controlled camera orbit was simple to understand and add to my own code. If I had found this video first it would have turned a 3 hour issue into a 20 minute one !

Camera Rotation Example

Here is the final product of today's work

I'm currently using this project as a method to improve my abilities in game design techniques, 3D modelling, C# programming and Unity as a game engine. I'm planning on writing about this project throughout the entire process to help reinforce the concepts to myself, and maybe help or inspire someone else along the way. Hopefully that will keep me focused and prevent it from falling into the ether like most of the rest of my side projects. All of this was coded on evenings and weekends in my spare time though, so I can't guarantee regular post releases. I'll do my best though !
If you have any suggestions for improvements or links to resources that would help me out feel free to leave a comment. All of the source code can be found on my GitHub.

You could also add me in game on OSRS if you play ! My ign is MapleThunder

Sort:  

That looks super cool! Keep up the good work :)

Congratulations @maple-thunder, this post is the most rewarded post (based on pending payouts) in the last 12 hours written by a Dust account holder (accounts that hold between 0 and 0.01 Mega Vests). The total number of posts by Dust account holders during this period was 4003 and the total pending payments to posts in this category was $780.46. To see the full list of highest paid posts across all accounts categories, click here.

If you do not wish to receive these messages in future, please reply stop to this comment.

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 64104.40
ETH 3148.52
USDT 1.00
SBD 4.25