What are some methods of detecting an object a certain distance in front of another instance of the same object. This would be best if it considered the direction the objects are facing, so it doesn't include all objects around it but only in front of it.
I would prefer if it didn't involve any detector type objects. Unless of course it works well with multiple instances of the same object.
I would run a loop to create and move an invisible object 1 pixel at a time from your object in the direction your object is facing. When the invisible (heaven forbid) detector object hits the other object, check the LoopIndex and this is the distance between the 2 objects.
Originally Posted by vetmora120 Hi Chris, thanks for your reply. Would this method make use of 360 degree directions? Would it also work with multiple instances of objects?
No, but you could use Chris' script to detect line-of-sight objects, then resort to using a circular Active Shape Object and a fastloop to detect ALL objects within a radius. That beats using raster active object detectors.
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?
Thanks for the example GrimFusion. I had never heard of the Active Shape Object before. Looks like it could come in handy.
I made up a little drawing of what I'm after just to be totally clear.
I'm struggling to find out how to achieve this using 360 degree rotation (think of it in top down). Essentially the 2 objects and line of sights are both instances of one object. So essentially its using just 2 objects. I'm not sure if using a seperate object for the line of sight in this scenario is the best solution since it's using multiple instances.
Maybe I'm too noob'ish to fully grasp what your trying to do, but can't you just add a single pixel to your sprite at the distance away that you want the collision, and use Fine Detection collisions? A single pixel won't likely be seen. Just make it the same color as the background.
My method will work for multiple instances and can work 360 degrees.
For 360 degrees, you should check for a break in line of sight ONLY if another object enters a certain radius (the length and field of vision) of your object. Otherwise you will be running 360 separate loops every frame, checking for breaks in line of sight in every direction. When you want to check the line of sight, find the angle the second object is from your original object and run a loop moving a single pixel detector one space at a time at that angle until it hits (or doesn't hit) the second object. You can even determine the length at which the line of sight was broken, using Pythagoras (a^2 plus b^2 = c^2) or tan.
It will work with multiple instances, but you will have to run a loop to check where the line of sight came from. First of all, don't break the line of sight with the object you are sending that line from. You will need to give your pixel detector an ID based on the object checking line of sight. Then when it is broken run a loop to find which object sent the line (based on the ID) and then make whatever you want to happen as a result of it.
Can't you use a set of coordinates and test at that spot if there is something? That's the normal way I would test, where the coordinate set is the y coordinate and the x coordinate of the object and then add a bit the x and y so you're testing in front of the object.
But I've no idea if that function already exists in TGF/MMF.
Another way is by using detectors which seemed to work fine for me even with multiple objects. But should always think up of situations for testing where you think it might fail, that way you will know it.