Help => Graphics => Topic started by: OrientatedCookie on May 01, 2015, 05:50:19 pm
Title: How to 'get distance' between two entities?
Post by: OrientatedCookie on May 01, 2015, 05:50:19 pm
Hello, can anyone give me some advice or point me in the right direction on how to get the distance between two sprites? What I want is to get the difference between two sprite's global position. I looked through the documentation and forums, but had no luck. I tried to do this but honestly have little idea:
That's a very random attempt. You try to check if one rectangle is less than the other -- there's not even such an operator, let alone are rectangles the right thing if you're talking of positions...
You should use the rectangle's centers. To calculate the distance, the function thor::length() (http://www.bromeon.ch/libraries/thor/v2.0/doc/_vector_algebra2_d_8hpp.html) can be helpful. You should have a look at basic vector algebra though; it's crucial to understand when working with SFML, even more so when developing a game.
Title: Re: How to 'get distance' between two entities?
Post by: OrientatedCookie on May 01, 2015, 08:56:51 pm
Indeed it is a very random attempt. I'm a university mathmatician graduate with 5 years experience in coding.