Hi, I am building a tower defence like game, and trying to keep it simple I have not used (yet) any kind of collision detection except collidesWith - the simplest collision detection function for gideros.
my enemy units move toward waypoints placed manually at the corner of the streets on a tilemap: the waypoints have id numbers and some property, and a simple AI chooses where the unit should go next.
Everything is fine, but i tried using bump to avoid units overlapping and it looks better, however I had to give up because I have different speeds between units, and each unit could be "frozen" or "slowed" for a certain amount of time, blocking the other units on the same path (they move on a specific axis only, and it is the same as the waypoints - which are axis aligned between them since they are built on purpose along straight lines).
To decrease units speed I skip some frames in the move() function of the unit, this way I can move units slower than 1 px/frame.
The issue is that above a certain number of units stuck together, the spawning others are moved on the other side of the queue (
after the "frozen unit" - in the direction where it was going) but they still think they have to reach a waypoint which is placed well before their current position (and they should do this, because there may be different paths to take). They are already bumping with the frozen one - which could also be unfrozen right now but it won't move because the others are pulling in the opposite direction to reach the previous waypoint... I don't know if I explained the issue well.. let me know
However, I was wondering if it could be possible to filter collisions between units with different speeds (my frame skip feature is bound to a
speed property so I can check if speed[1]>speed[2]) in some way that the faster unit could overlap with the slower one and get through it without issues. The best thing would be that while overlapping it moves by some pixel aside.. but I am still thinking on how to do this: it should not be cpu killing.
Does anyone had the same problem? How did you solve it?
Thank you
Comments
If you are using a grid system to find paths for your units you could always set the grid cell of each unit to a solid state so when other units are path finding they will not enter that cell. This would most likely work but you would have to be performing a lot more path finding which would eat CPU time. Something like this maybe..
There is some flocking behavior code here in Lua that can be modified to work in Gideros (it's Lua code so 99% of the work is done). In The Nature Of Code, flocking is discussed at 6.13
The only issue is how much CPU time this eats. In my own experiment with this kind of thing I stagger the checks between game objects. By stagger I mean game objects only calculate avoidance every n frames like this..
Likes: Atavismus
I like bump:queryRect, I didn't saw it :-B I will give it a try
Have you seen the bump function to query a segment (line)???
So project a line out in front and check. If there is nothing there then keep moving forward. If the line is intersected by another object, and that object is moving slower than this object, then steer away in some direction.
I think that might be a solution. Let us know if you can't figure it out
also.. this github page for the original bump.lua is a fantastic document
https://github.com/kikito/bump.lua
Likes: pie
Likes: antix