HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Collision detection Algoritm

11-02-2007, 01:34 PM#1
MaD[Lion]
Ive been using ForGroup and EnumUnitInRange for thw collision thingy... but i came up with another method that i think is faster, but im not sure.
This method only check globals (array) in a loop... i wonder if this is better.

It doesnt check every a unit with every unit. But It checks the unit's tat is close to it... in a way i though of.
But i am not sure if EnumUnitInRange is faster than checking globals...
Also the global method im talking about shouldnt have more loop than the amount of units nearby... and ofc it avoid double check for each unit.
11-02-2007, 02:04 PM#2
moyack
I think the efficiency depends of which operations are you doing in your code, not if they are done on globals.

IMO, EnumUnitsInRange is very efficient.
11-02-2007, 03:06 PM#3
MaD[Lion]
yes... but i want it to be even mor effecient

But my idea basically is running trough a loop of collidable unit in an array. The units will be ordered after their coordinate X+Y. so to check the units around them i just for each of them: check the nearby array indexes for the units tat is within range
11-02-2007, 03:37 PM#4
Toadcop
Quote:
IMO, EnumUnitsInRange is very efficient.
yes. *NOTHING IS FASTER* ... ^^ if no units are there so it's costs almost nothing. (~2x GetTriggerUnit()) (performance) so forgeit better jass solutions. some custom natives will maybe help you BUT ^^ well.
11-02-2007, 03:38 PM#5
cohadar
Quote:
Originally Posted by MaD[Lion]
Ive been using ForGroup and EnumUnitInRange for thw collision thingy... but i came up with another method that i think is faster, but im not sure.
This method only check globals (array) in a loop... i wonder if this is better.

Yes it is.
In my map I have a physics engine based on Collections and PUI (and structs ofc).
It is faster than using ForGroup because there is no attaching of engine vector parameters to units.

EDIT:
This only applies to movement/acceleration,
I don't have collision detection in my engine (nor I plan on implementing one)
I do have a ground-hit events thou, that is all you need to make complex movement.
11-02-2007, 05:57 PM#6
MaD[Lion]
cohadar ground collision and movement/acceleration is no problem, i have very fast one too. Without forgroup. But its collision detection with other units tat i wanna speed up here. It is fast, but i want fast... I msut make it work XD
So is globals FASTER than EnumUnit ?
11-02-2007, 06:14 PM#7
Toadcop
Quote:
So is globals FASTER than EnumUnit ?
in practice... NO ^^ EnumUnits it's the optimal solution. (you will operate only with "needed" units) the "section" (virtual groups) construction have flaws.
it's the same story like with Custom Sin\Cos ^^
11-02-2007, 08:41 PM#8
grim001
there is no faster method than groupenum.
11-02-2007, 10:01 PM#9
MaD[Lion]
i see, ok thnx for the confirmation, YAY no need to waste time on crap :P
11-03-2007, 03:49 AM#10
cohadar
Quote:
Originally Posted by grim001
there is no faster method than groupenum.

I do not believe in this for 2 reasons:

1. I did not try it out myself
2. I found out that for moving/acceleration global arrays are faster.

Now I don't know about collision, never tried to make it so I simply cannot be the judge there.
But neither can you unless you actually tried and made 2 implementations,
one with arrays and one with ForGroup, and then compared them.

Did you?
11-03-2007, 12:51 PM#11
Toadcop
cohadar EuniUnits is faster than to loop (2 !!!) units and check the distance ! and to check distance between 2 units is the best case.

NATIVES PAWNZ JASS SUCK ! =)
11-03-2007, 01:10 PM#12
The Kingpin
If you think about it, it would be faster to perform an action involving units within x of a point, rather than every collidable unit in an array, regardless of where it is.

It would get more laggy the more collidable objects you create, too.
11-03-2007, 02:06 PM#13
cohadar
Quote:
Originally Posted by Toadcop
cohadar EuniUnits is faster than to loop

Oh I know that, but we are not just comparing ForGroup vs loop
there are some speed benefits to be gained by using arrays vs groups,
I am simply stating that I don't believe anything until I test it myself,
no matter how logical it might seem.

Besides you people should have learned so far that logic and Jass don't mix very well.
11-03-2007, 02:50 PM#14
MaD[Lion]
Quote:
Originally Posted by cohadar
Oh I know that, but we are not just comparing ForGroup vs loop
there are some speed benefits to be gained by using arrays vs groups,
I am simply stating that I don't believe anything until I test it myself,
no matter how logical it might seem.

Besides you people should have learned so far that logic and Jass don't mix very well.

i also though of this before. But i actually made a version of my collision detection with loop, and it proved tat loop isnt better.
I even intergrated it into just 1 loop tat both check collision and move the units. But still not faster. So if u want a confirmation I CAN CONFIRM that forgroup and loop is the same.

But i have not tried to replace it all with just loop.
The thing with EnumUnit is that it require u to use ForGroup or to remove units from group... these extra natives may be wat tat make it slow, not EnumUnit itself.
But if i only use globals, tat may be better? i dont know. Have anyone tried this? or shall i try it :P
11-03-2007, 03:24 PM#15
DioD
ForGroup() + UnitUserData()

vs

Loops + lists

There is no need of loops if unit user data can be used.

I have demo map for this stuff, can post if any one needs it