Sign in to follow this  

Re:Distance to target check

Recommended Posts

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
distance - characterradii < range where characterradii = raidusofa + radiusofb

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

Share this post

Link to post
Share on other sites
distance < range + sum_of_radii

distance^2 < range^2 + 2*range*sum_of_radii + sum_of_radii^2

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 this post

Link to post
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 this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this