The Daily Click ::. Forums ::. Klik Coding Help ::. Collision Detection
 

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  07/01/2010
Points
  273
29th March, 2012 at 29/03/2012 06:14:13 -

Hi all,

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.

All ideas and feedback welcome!

Edited by vetmora120

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
29th March, 2012 at 29/03/2012 07:18:24 -

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.

Let me know if you need an example

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
29th March, 2012 at 29/03/2012 22:57:27 -

Hi Chris, thanks for your reply. Would this method make use of 360 degree directions? Would it also work with multiple instances of objects?

 
n/a

The_Antisony

At least I'm not Circy

Registered
  01/07/2002
Points
  1341

VIP MemberStarSnow
30th March, 2012 at 30/03/2012 17:07:31 -


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.

I made an example a while back that uses the object. It's not exactly what you're after, but go ahead and mod it out. No need to bother with credit.
https://skydrive.live.com/redir.aspx?cid=3b49ffb7b0bb8733&resid=3B49FFB7B0BB8733!143&parid=3B49FFB7B0BB8733!129&authkey=!ABKwnGkE99IWqLw

Edited by The_Antisony

 
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?

vetmora120



Registered
  07/01/2010
Points
  273
4th April, 2012 at 04/04/2012 05:15:10 -

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.
Image

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.

Edited by vetmora120

 
n/a

infinitum3d



Registered
  03/03/2012 22:18:24
Points
  66
4th April, 2012 at 04/04/2012 14:07:48 -

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.

Edited by infinitum3d

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
4th April, 2012 at 04/04/2012 17:14:17 -

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.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
4th April, 2012 at 04/04/2012 17:17:05 -

Further reading: http://www.create-games.com/forum_post.asp?id=293862

Sketchy's final comment in particular. There may even be a few examples on there too.

 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2723
4th April, 2012 at 04/04/2012 19:59:01 -

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.


 
Image jenswa.neocities.org
   

Post Reply



 



Advertisement

Worth A Click