• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Collisions with other obj_units in RTS

M

mtski

Guest
Hi guys,

So, I am attempting to make a collision system between many obj_unit objects. I have successfully implimented my own drag, select and set target system that these objects follow.

My issue is with collisions between these objects. I'm mostly trying to practice with GML at this point so I do not want to limit ideas on how this might be handled.

At this point, I have set a "Collision Event" for the obj_unit, but upon having many in the room, they just get stuck on one another and I'm not sure how I should have them handle separating to continue their course to their target. Any ideas on this?

I have though about looking into pathing, but I have no experience with pathing. Is it possible to use something like place_meeting(x + dir, y + dir, obj_unit)? - Iv noticed this is completely incorrect as dir is just a number and does not translate well when used in this function. But maybe there is a way to implement this?

Thanks for any advice
 
M

mtski

Guest
Thanks, I will check these out.

Do you think pathing would be viable here as well?

Can you provide an example of how I could implement lengthdir functions and how they work? I have a rough understanding of what they do, but I am still not sure how I might integrate these functions.
 
Last edited by a moderator:
K

ktiix

Guest
The manual page for length_dir_x and _y has examples there.

If you have so many units that they are getting bottlenecked and colliding with each other, getting them all to follow a single path might exacerbate the issue. Maybe add some random movement to them to help spread them out a bit.
 
M

mtski

Guest
Iv considered random movement as well. Thank you for your responses btw.

Once I get some time I will be playing with length_dir in gml to figure out how these functions work. Once I get a full understanding I'm sure I can find a way to use them.

What about logic though? I dont have any noticable lag unless I create like 700 instances lol. But I'm only just learning. I'm trying to see if I can figure out the basics of an rts system for future development.

Logic as in: should I have all selected obj_units take a route or path that is alongside one another, or can I have them constantly checking and avoiding collision on their way to their destinations?
 
T

Taddio

Guest
One of the classic way to do it is use a single path for all your selected units, and use a flocking algorithm (use Google to find the classic ones, you probably will have to make some GML port, I don't know of any ready-made ones) to make them steer in a nice-looking and smooth way, without your units stacking on top of each other, or constantly pinballing becaause of different speeds, etc.
Think of little magnets that repulse each others individually, but when they are selected and you click on the map, they are ALL attracted towards there, even if they have a "repulsive field" between themselves.
All in all, I just suggest one path per UNIT GROUP, not a path per unit, especially if you have a ****load of them!
 
Another thing to consider is when you find yourself unable to move (lets say there's a clog of units at a choke point), set a timer for a random amount of time (between 1 and 5 seconds) and then check again before trying to move. This makes it so the units find themselves unable to get through so they wait and hopefully the unit in front will move through, then a few timers go off checking, and the next few units that can move through, etc. This stops them bumbling around like fools while they are stuck in a position.
 
M

mtski

Guest
Sorry, I forgot to respond to this. I was able to make things less crazy by unchecking "Solid" within the objects. This has been ok for me for now and I was able to come up with a simple collision solution.

Also, I made it so that each of the units was able to locate their target locations and move accordingly with not so harsh collision checks in a way they sort of bounce around each other. I did not have to use lengthdir for this. I will be soon for other functions though.

I've come across a new problem where GMS2 keeps randomly deleting my sprite assets as I draw new ones. Could this be from using the built in sprite editor? Where can I get a solution for this. Im going to create a dedicated post for this issue.
 
T

Taddio

Guest
Sorry, I forgot to respond to this. I was able to make things less crazy by unchecking "Solid" within the objects. This has been ok for me for now and I was able to come up with a simple collision solution.
Basically, never check 'solid' unless you really know what it's doing and you're 100% sure you need it.

I've come across a new problem where GMS2 keeps randomly deleting my sprite assets as I draw new ones. Could this be from using the built in sprite editor? Where can I get a solution for this. Im going to create a dedicated post for this issue.
This shouldn't happen, built-in editor or not.
 
Top