Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411595 Posts in 69386 Topics- by 58445 Members - Latest Member: YomiKu_0

May 07, 2024, 08:11:30 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[GML] Tile Based Movement in Real Time
Pages: [1]
Print
Author Topic: [GML] Tile Based Movement in Real Time  (Read 1422 times)
Doctor Universe
Level 0
**



View Profile
« on: March 22, 2009, 07:42:31 PM »

Hello all! I've got a question that probably has a rather complex answer! Anyway. I need help getting units to move based on tiles (or a grid, what have you). I need this to be in real time for the concept to work. Likewise, I Would prefer the units to not pass through each other, assuming a criss-cross is requires during one of the movements. ( Basically I want them to move around each other, instead of through). If this is too vague, just let me know and I'll clarify, thanks.
« Last Edit: March 31, 2009, 04:39:23 PM by Derek » Logged
ChevyRay
Guest
« Reply #1 on: March 22, 2009, 07:56:12 PM »

Just set a destination position. For example, if you want them to walk to where you click the mouse, you'd go:
Code:
walkto_x = ((mouse_x / grid_w) div 1) * grid_w;
walkto_y = ((mouse_y / grid_h) div 1) * grid_h;

grid_w and grid_h would be the width and height of your grid squares.

If you already have the correct position, just set walkto_x and walkto_y to where you want it to go.

Anyways, have them move towards that position, avoiding collision with other units while doing so. You could always just have them stop moving while a unit occupies the next position, so if they "criss-cross", one will always stop and let the other pass first.

I'm not 100% clear on what it is you need exactly, but if you can't get it to work, I'll write up an example for you.

EDIT: also, there is a "game maker" message icon you can specify for your post, to let you know you are working with GML. Derek just added these recently, I believe.
« Last Edit: March 22, 2009, 07:59:28 PM by ChevyRay » Logged
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #2 on: March 23, 2009, 10:02:39 AM »

Is this a 2D plane viewed from above? If so, and if we ignore terrain and consider the arena a perfect plane, then you could relatively easily solve this my bounding spheres and simple vector math.

Each unit has a bounding sphere around it of radius r. Each unit move along their ideal vector toward their goal. If two bounding spheres intersect each move one step along the right axis to the vector between the units' positions [right = crossp(other->pos - this->pos, vector(0,1,0));]. If that too is a collision, let that unit wait, and on a plane any pile-up will sort itself out from the edges.
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic