# Re:Distance to target check

This topic is 2445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi
So normally a distance check would be done by simply doing distance < range check. So lets say distance between character a from character b.
However to optimize one would do d^2 < r^2 check.

However if one has to include the radius of each of the characters then the check would be

I'm trying to think of some way where I could keep the squared optimization and also be able to include the radii part.
Thoughts??
I'm discounting this one
(d^2 - r^2)/(d+r)
as that will need the square root value of d
Thanks.

##### Share on other sites

You should be able to precompute everything on the right-hand side and then the check again becomes distance^2 < constant. So no square root needed.

##### Share on other sites
Good suggestion.
Do you think its worth doing this addition and multiplication operations over doing square root of distance though?
Plus I will either have radius or radius^2. So if I have radius then I will have to square it and if I have radius^2 then I will have to root it. lol.
Or I would have to save both. Probably not a good idea to double data storage.

##### Share on other sites
Basically I have distance^2, range^2 and radius of each character and I want to keep it the most optimized.
Looks like its going to have to be d - r < range check.

##### Share on other sites
Multiplications and additions are much cheaper than square roots. Don't bother storing the squares of numbers, because they are easy to compute.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013607
×