Jump to content


Photo
- - - - -

Rts Tutorial 1


  • Please log in to reply
38 replies to this topic

#1 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 16 June 2010 - 12:56 AM

  • Title: Easy Top-down --> Isometric Converting
  • Description: Easilly converts back and forth between isometric and top-down.
  • GM Version: GM 8 (But the scripts alone should work with older versions of Game Maker)
  • Registered: Probably not.
  • File Type: .gmk
  • File Size: 0.02MB
  • File Link: Download Here
Additional Info
The example isn't too flash but the engine is very capable. Hope you like it! Credit would be lovely, but not required. Apologies about the game info btw. I was originally going to write the tutorial there but I decided on the site here was a bit nicer. THis way people can see the functions before they download. YAY!


Isometric Rendering

Posted Image

Isometric is a perspective without perspective (ha! a witty opener) and I still don't know of a simple way to explain it (hence the Age of Empires image). Basically it takes the x and y axis and puts them on angles, then adds a third axis (z) in the upwards direction. Its often used in tech drawing, but became quite popular during the 90's in rts games. Sadly it has almost died out, but that's what we are here for! So shall we get started?


The Process


So one day, having done a bit of research into this isometric business, it occured to me that calculating EVERYTHING in isomtric was very difficult. Almost as hard as calculating regular 3d, so I tried to think of ways my poor little artist brain could understand it. The conclusion I eventually came to was this engine.

Basically what happens is the entire game is calculated like a top-down game, until it comes time to render the thing. Before it is drawn, all instances calcuate their isometric co-ordinates and they are drawn there instead. This gives the illusion of isometric, while allowing for all of Game Maker's other functions to be used in a simle way (mp_grids for example). This was a break through for me because all of a sudden I had a very simple way of transferring top-down movement (which lets face it is rather boring) into psuedo 3d movement! And I didn't even need to do any of those stupid calculations where I need to reduce speed by half when moving vertical and pathfind around diamond tiles etc.

The other great thing about only drawing in isometric is its REALLY easy to change the view-point of the game. Thaaaaaaaat's right, this engine can render in four different view points (NE,SE,SW and NW), and possibly even top-down if you make it so. Anyway without further ado, on to the engine itself.


The Isometric Engine


To start with we need to set up the game to allow isometric rendering. There is ONE function that will do this for you

iso_start(factor) Begins viewing the room in an isometric projection.


Now what this does is sets up all the variables needed for the isometric engine to work, so MAKE SURE YOU CALL IT BEFORE ANY OTHER FUNCTION. factor refers to the ratio of the y axis to x. So if we want the 'diamond' to be half as tall as it is wide, all we need to put here is 0.5 and done.

Note: In this isometric engine the co-ordinates actually work the opposite way to what you would think. In the 'top-down' processing, everything needs 3 co-ordinates, so that the isometric position can be calculated but when it comes to the isometric rendering, we actually only need two, x and y, because we are talking in terms of the position on the screen rather than the position in the room. The screen is 2d, the room 3d catch my drift? Hope that's clear enough.

Once we have the game set up there is another thing we can do that's very simple and that is set the projection.

iso_set_projection(direction) Sets the direction in which the world will be viewed.


The game automatically sets itself to North-East projection but this can be changed to 3 other directions, each with a corresponding numerical value.
So for direction, 0=North East, 1=South East, 2=South West and 3=North West. Nothing else needs changing for all the other functions to work correctly.


Calculating Position

So once we have the easy stuff out of the way, its time to get on to the truely useful functions. These functions calculate an objects drawing co-ordinates, based on its 3 dimensional position in the room.

iso_get_x(x,y,z) Function returns the x co-ordinate used for drawing the instance in isometric.

iso_get_y(x,y,z) Function returns the y co-ordinate used for drawing the instance in isometric.


Easy enough? Before you draw, simply call these functions to find the x and y positions wher you should draw

Note: Make sure you take a look at the spriting tips below to ensure the position is correct.

So what happens if we have something on the screen like the mouse? Remember mouse_x and mouse_y are no longer the mouses position in the room, they are its isometric drawing co-ordinates. To get its real position, we need to perform the following functions.

iso_get_regx(isox,isoy,z) Function returns the x co-ordinate based on isometric co-ordinates.

iso_get_regy(isox,isoy,z) Function returns the y co-ordinate based on isometric co-ordinates.


Sweet as, we whizzed through that, now onto the next show!


Easy Depth

Depth is a problem that always plagues isometric engines. The depth in this engine works in layers. Let me explain. Everything with the lowest isoy co-ordinate and the lowest layer number will be drawn first. Then the stuff with the same isoy, but a higher layer number will be next. Then once all the layers are drawn, the engine moves onto the next lowest y value. This way, the closer to the bottom of the screen stuff is, the closer it gets to the viewer, make sense? For this to work we need to define the number of layers we wish to use.

iso_set_depth(depthmin,layers) Sets the depth to be used in the functions.


Now depthmin refers to the depth to use for the top layer at the bottom of the drawing field, and layers is the number of layers to use in the room. Now though this depth seems very limited, it is really useful for flying instances or clouds.. i dunno, I haven't eplored many possibilities. Once improvement that I have only considered as I write this is to allow multiple depth grids. So for example, having the tiles all in a depth grid, so that tiles can overlap with the correct depth, but having them all behind another depth grid, which is used for the instances. Note that that is not currently possible with the engine, but I'll get to work on it straight away.

Anyways back to depth. When it comes to the actual calculation there are two possibilities

iso_get_depth(isoy,z,layer) Returns a depth value based on the units position in the room.


This function can be used to get the depth of instance based on its position in the room. HEED THIS WARNING: This will use a HUGE number of depth values, especially for larger rooms, so this should only really be used on things that wont have their depth updated in every step (tiles for instance).

The other function is much more useful in my opinion

iso_get_depth_view(isoy,z,layer) Returns a depth value based on the units drawing position in the view.


(There is a typo on this in the script, it says room instead of view)
This function takes the minimum drawing position to be the bottom of the current view, so only uses depth values that are currently needed (as we don't need to be drawing anything that's outside the view do we :D)


The End?

NO OF COURSE NOT. Sure I have run out of functions to throw at you but I can still be a bother by giving you some handy hints.

TIP 1 - Masks
EVERY object in your game will need a mask for its top-down collisions. Because its not being auto-drawn, it needs to keep a mask at its top down position to have any sort of presence in the room.

TIP 2 - Center of the image
The example doesn't really show this because it doesn't handle collisions but if you want to do collisions, where you place the 'origin' of the sprite is important. This requires some visualisation on your part. If your sprite has a square mask, try to visualise this square in isometric (it will become a diamond) Now chuck this diamond onto your sprite. Even if on your mask the origin is in the middle, chances are you wont want it in the middle for your sprite. THe diamond should be at the foot of your soldier, so the middle of the diamond will actually be towards the bottom of the sprite. I hope I haven't confused anyone with this, just be careful is all I'm trying to say haha.

TIP 3 - Oh, I only had two tips :(

I hope you guys found this tutorial useful. There'll be more RTS goodness soon, have fun with it!
  • 4

#2 krele

krele

    GMC Member

  • GMC Member
  • 623 posts
  • Version:GM:Studio

Posted 08 July 2010 - 09:06 AM

Why, why, WHYYYY do people just ignore awesome stuff like this?...

You made something brilliant, being glad to share your knowledge, and people do nothing. They don't give any feedback...

Let's just face it, GMC sucks and is overrun by script kiddies that just wanna download an uber-cool-ultimate engine to make the game for themselves...

Too bad =/... This engine is awesome =)
  • 0

#3 Shadowrend

Shadowrend

    Master of Shadows

  • GMC Member
  • 2996 posts
  • Version:GM8

Posted 08 July 2010 - 10:07 AM

Indeed. This is awesome.
  • 0

#4 zeldarules28

zeldarules28

    GMC Member

  • GMC Member
  • 215 posts

Posted 08 July 2010 - 04:03 PM

I saw this too, and its really cool. I downloaded it yesterday and I like it, but Im not skilled in rts programming enough to do this. Well..maybe sort of.. If I start working on an rts Ill definntly use this. Ive been looking for a tutorial on how to do this. Thanks!
  • 0

#5 Phantom107

Phantom107

    Graphics Enthusiast

  • GMC Member
  • 2665 posts
  • Version:GM:Studio

Posted 08 July 2010 - 04:07 PM

You know, the problem with RTS tutorials is that the novice users cannot make a game out of it, and advanced/expert users write their own system anyway.
  • 0

#6 ga05as

ga05as

    GMC Member

  • GMC Member
  • 880 posts

Posted 18 July 2010 - 09:57 PM

I haven't tested this out yet, but it sounds very good.
I am going to extend this for my purposes. and this will REALLY help with my game.
Thanks very much.
If i finish it. You can have credit :P
  • 0

#7 freko

freko

    The Professional

  • GMC Member
  • 504 posts
  • Version:GM8

Posted 19 July 2010 - 12:27 PM

Has anyone made an iso RTS map editor :( . I really need one
  • 0

#8 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 19 July 2010 - 06:09 PM

Damn, at first I thought that was a screenshot of the examplePosted Image Still awesome though.

EDIT: I worked on your .gmk a bit. I added in a way to create+draw correctly iso backgrounds starting only with a top down background (plus I added in some iso blocks).
If you want it, here's a link to the .gmk:
Iso test1.gmk

Edited by CaptainLepidus, 19 July 2010 - 07:39 PM.

  • 0

#9 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3534 posts
  • Version:GM:Studio

Posted 20 July 2010 - 12:22 AM

Awesome tutorial, i was looking for something like this some time ago... i spent like two days trying to figure out how in hell can i make and isometric pacman game xD (it wasnt even a project... i was bored :( )
  • 0

#10 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 24 July 2010 - 03:44 AM

I just had to bump this because this is an awesome example and it shouldn't fall off the first page.
  • 1

#11 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 24 July 2010 - 10:33 PM

Hey thanks for all the replies! Sorry I hadn't replied sooner, I actually forgot about this tutorial given all the work I'm doing for comp06 :/ oops hehe.

@ Krele && Shadowrend && manuel777
Thank you so much :D Any suggestions for the next version?

@ Zeldarules
I have tried to make everything as clear as possible so that you don't need to understand the internal workings of the scripts, but if it gets too confusing, let me know and I can go over with you step by step using the engine.

@ Phantom
Much truth in your words my friend, I just thought since this is a bit of a different way of thinking I better post it haha.

@ Freko

Has anyone made an iso RTS map editor. I really need one


They're really easy once you know how much you need to put into them. If you pm me with more specific questions I can help you out.

@ CaptainLepidus
Thanks dude I'll check out your improvements when I get home, I'll try include them in the next version. What would you like to see improved? Thanks for the bump too haha
  • 0

#12 jackyboyhenry

jackyboyhenry

    just jack

  • GMC Member
  • 466 posts

Posted 27 July 2010 - 10:57 AM

Why, why, WHYYYY do people just ignore awesome stuff like this?...

You made something brilliant, being glad to share your knowledge, and people do nothing. They don't give any feedback...

Let's just face it, GMC sucks and is overrun by script kiddies that just wanna download an uber-cool-ultimate engine to make the game for themselves...

Too bad =/... This engine is awesome =)

Im a kid.. and.. i like this engine :D
  • 0

#13 peceecar

peceecar

    GMC Member

  • New Member
  • 321 posts

Posted 28 July 2010 - 01:27 PM

i can not thank you enough for this it will grately help me with the design of my own projects
  • 0

#14 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 28 July 2010 - 08:28 PM

Wow more and more compliments, thanks heaps guys! Any improvement suggestions though? I can't work on the engine atm but after competition06 I will be creating a new version. If you want to have input lemmie know now.

Cheers
  • 0

#15 freko

freko

    The Professional

  • GMC Member
  • 504 posts
  • Version:GM8

Posted 29 July 2010 - 04:52 AM

Wow more and more compliments..

And more to come ^_^

Edited by freko, 29 July 2010 - 04:58 AM.

  • 0

#16 leocesar

leocesar

    GMC Member

  • New Member
  • 25 posts

Posted 26 August 2010 - 07:53 AM

I love people like you! great tut.
  • 0

#17 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 26 August 2010 - 04:48 PM

Note about my addition to the example: make sure you go to global game settings and turn off Interpolate between pixels to get a good look.
  • 0

#18 Hillstrom

Hillstrom

    GMC Member

  • New Member
  • 28 posts

Posted 28 August 2010 - 07:01 PM

And don't forget that this tutorial/example also work for any kind of game type, not only RTS.
Even works for parallax games, (Zelda, 16 bit RPGs), again just messing with the draw events only. I am right... Right?
The only thing this Top View => Isometrics conception doesn't solve by itself is "jumping", but for RTS is just the way to go.
  • 0

#19 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 02 September 2010 - 09:58 AM

I love people like you! great tut.


Why thank you, it's great to hear.

@ Captain Lepidus, I am kinda embarrassed that you had to effectively create a new example for yourself since mine was so useless lmao. In fact that is an apology to you all, my example is aweful. I am hoping so release an example of how to use this engine for rpg style games and rts when I release the next version (hopefully after uni finishes up for the year). I promise it will be good. the way I figure it the depth needs to be easier to use, but is there anything else you would like to see in the next version? Anyone? Last chance... (Well not really, uni still has a while yet)

Oh and @ Hillstrom, yes it can be used for jumping. If you add a z co-ordinate to the object you want to use it, you'll be all good.
  • 0

#20 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 02 September 2010 - 09:18 PM


I love people like you! great tut.


Why thank you, it's great to hear.

@ Captain Lepidus, I am kinda embarrassed that you had to effectively create a new example for yourself since mine was so useless lmao. In fact that is an apology to you all, my example is aweful. I am hoping so release an example of how to use this engine for rpg style games and rts when I release the next version (hopefully after uni finishes up for the year). I promise it will be good. the way I figure it the depth needs to be easier to use, but is there anything else you would like to see in the next version? Anyone? Last chance... (Well not really, uni still has a while yet)

Oh and @ Hillstrom, yes it can be used for jumping. If you add a z co-ordinate to the object you want to use it, you'll be all good.


No, this is an awesome example! I just wanted to see what I could do with it. Seriously, I would never have figured out how to convert top down to isometric by myself.
  • 0

#21 mortalpico

mortalpico

    GMC Member

  • New Member
  • 556 posts

Posted 04 September 2010 - 12:13 AM

can you make a GM7 version of it?
  • 0

#22 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 14 September 2010 - 10:24 AM

can you make a GM7 version of it?


Lol fair point... Ummm I uploaded the scripts somewhere hang on... Here! It wont have an example but hopefully my explaination of the scripts will be enough to help you out. I will try remember to upload a GM7 version with the update.

Cheers for the replies!
  • 0

#23 weckar

weckar

    Helping Hand

  • GMC Member
  • 2533 posts
  • Version:Unknown

Posted 14 September 2010 - 01:36 PM

If only it was easier to do iso human sprites... or to rip them xD
  • 0

#24 goldage5

goldage5

    GMC Member

  • GMC Member
  • 152 posts

Posted 02 March 2011 - 01:32 AM

:(*crying* aaaawww!!!! this doesnt work in lite!!!!!!! :( :( i hate it when my computer breaks!!!!!:angry: :angry:

would it be possible to make a lite version of this??? pleaaase????
  • 0

#25 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 03 March 2011 - 08:59 AM

I'm pretty sure the scripts all work with lite. I'm pretty sure this example will too. Hopefully this helps. :) I got a bit of a suprise to see this old beast pop back up on the community, I should really update it.
  • 0

#26 SimplySeth

SimplySeth

    GMC Member

  • GMC Member
  • 79 posts
  • Version:GM:Studio

Posted 09 March 2011 - 07:35 AM

Finally!! I've been trying to figure out this whole isometric calculating thing and I never thought of rendering it like that. My method always led to complicated room setups and way too many bugs.

One thing I'm struggling with your engine though. I don't understand your rotate script or the physics you use for moving. I tried manipulating them but I can't seem to shake the "balloon" physics if you know what I mean. The unit will travel around in circles around the goal and it will never reach its destination. What would be the easiest way to make a unit travel from point A to point B without any of the unnecessary 'turning' or 'circling'?



Good job on the engine and keep up the good work!

Edit::

Nevermind, problem mostly solved.

Edited by SimplySeth, 09 March 2011 - 07:56 AM.

  • 0

#27 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 09 March 2011 - 08:40 AM

I know you said you mostly solved it but it's a good point that needs re-stating, and this goes for everyone. Make everything like you would in a top down game, movement included. Only the drawing needs to be isometric. Thanks btw, I should really actually make some other RTS tutorials... lol. But it is always nice to see this pop up on the first page of the tut list :)

Rani
  • 0

#28 Boysano

Boysano

    GMS Pro Member

  • GMC Member
  • 334 posts
  • Version:GM:Studio

Posted 10 March 2011 - 06:51 PM

I know you said you mostly solved it but it's a good point that needs re-stating, and this goes for everyone. Make everything like you would in a top down game, movement included. Only the drawing needs to be isometric. Thanks btw, I should really actually make some other RTS tutorials... lol. But it is always nice to see this pop up on the first page of the tut list :)

Rani


Thanks so much for this!

I'm new to GM8, just got my pro version, did all the basic tuts and started developing my own RPG/RTS game and this solves most of my first issues already lol - like getting a unit to travel to destination even after i unselect it.
And making the selection block (rectangle) with mouse outline and show transparent in it. Very nice.

I hope my graphics designer friend will keep up with the iso method :) I'm already seeing diamonds.

thanks, hope to see more
  • 0

#29 Rani_sputnik

Rani_sputnik

    GMC Member

  • GMC Member
  • 426 posts
  • Version:GM:Studio

Posted 10 March 2011 - 08:03 PM

Cheers Boysanyo.

I have an idea for the new version finally!

Better example
New functions (see below)
Easier to use! :o *what? How?*

My idea is this. You call iso_start() to begin using the iso engine.
Next in each object you want isometric, you simply call iso_instance_create() and this script automatically adds a littl script into that objects step end step event which updates the isometric co-ordinates. These co-ordinates are stored in the object as isox and isoy.
Then all you need to do is use them like built in variables for the object! Likewise depth will also be updated in this manner... oooh excitemtent.
But of course I'll have a function to switch off this automatic updating and it can be stopped with iso_end too.
Two functions -> object is ready to use, can't get much easier than that right? I'm at uni all day so I don't know when I'm gonna work on it, but I hope it's soon.

Let me know if any of you have any more ideas for the engine, cheers!
Rani.

I suddenly thought, wait what if they change the projection during the step event???? *scandal* also depth is based on position so best do it after all the moving is done

Edited by Rani_sputnik, 10 March 2011 - 08:05 PM.

  • 0

#30 SimplySeth

SimplySeth

    GMC Member

  • GMC Member
  • 79 posts
  • Version:GM:Studio

Posted 11 March 2011 - 06:49 AM

Quick question...

I know how to solve the movements but the sprite drawing is confusing me.

I used a system of arrays to check if the sprite is standing, walking, attacking, etc. the state is later defined by the variable 'state' when the character is walking, standing, etc.

So my creation code looks like this.

/*set the IMAGE CHECK variables 
state
0 = stand
1 = walk 
2 = attack

sub-state
0 = up
1 = down
2 = right
3 = left
*/

//for standing
state_anim[0,0] = spr_conscript_upstand;
state_anim[0,1] = spr_conscript_downstand;
state_anim[0,2] = spr_conscript_rightstand;
state_anim[0,3] = spr_conscript_leftstand;
//for walking
state_anim[1,0] = spr_conscript_upwalk;
state_anim[1,1] = spr_conscript_downwalk;
state_anim[1,2] = spr_conscript_rightwalk;
state_anim[1,3] = spr_conscript_leftwalk;

I obviously don't get the math. When call the different directions in the draw event, it bugs out and only works for some directions.

if direction < 315  && direction > 45 {draw_sprite(state_anim[state,2],-1,iso_get_x(x,y,0),iso_get_y(x,y,0));}
if direction < 45 && direction > 135 {draw_sprite(state_anim[state,0],-1,iso_get_x(x,y,0),iso_get_y(x,y,0));}
if direction < 135 && direction > 225 {draw_sprite(state_anim[state,3],-1,iso_get_x(x,y,0),iso_get_y(x,y,0));}
if direction < 225 && direction > 315 {draw_sprite(state_anim[state,1],-1,iso_get_x(x,y,0),iso_get_y(x,y,0));}



so is iso_get_x and iso_get_y for projecting any instances on the screen? or is just to place the object itself and not used for drawing sprites in the draw event?

Sorry, i'm super confused :blink:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users