Using “Magnitude” to calculate distance between objects…
computerking9979
Member Posts: 11
Hi everyone,
I have seen a couple of videos (though kinda old) that show using the magnitude function to calculate the distance between objects. However, I’m not able to follow along because the interface is different (they are on a Mac and I’m on a PC, but it also could be the age of the videos).
So could someone tell me how I use the magnitude function to calculate the distance between 2 or more objects?
Thanks in advance.
P.S. Is magnitude the only/best option to find the distance between 2 objects or is there a behavior for it?
Comments
I don't have the Windows version available to me ATM but the high level:
Preview and you should see a distance. If you want the distance to always be positive, then wrap magnitude in an abs function.
Hope that helps!
I think this makes sense.
I’m making a top down scroller where the enemies won’t start shooting until the player is within a certain range. So each enemy would do this calculation individually.
So would I put the constrain attribute behavior set to self.distanceToTarget in each enemy?
Thanks for your help.
Yes, so each enemy would calculate it's distance to the player and the player would be the "target" in this case.