Data Realms Fan Forums
http://45.55.195.193/

Detect if there is terrain within a certain range?
http://45.55.195.193/viewtopic.php?f=73&t=24596
Page 1 of 2

Author:  deathbringer [ Sun Jul 17, 2011 9:28 pm ]
Post subject:  Detect if there is terrain within a certain range?

Ok so for some reason I want to detect if there is some terrain within a certain range next to an object.

Ex : My object is a missile. I want it to blow up just before it hits something.

Actually I don't really care how the detection is made I just want to know a way to do that ^^ I tried to make it with GetAltitude but it just don't calculate whats in FRONT of the object, which is annoying :/
I'm pretty sure there is some very simple way to do it but I'm clearly a noob at lua.

Btw, this object is an AEmitter.

Author:  Abdul Alhazred [ Sun Jul 17, 2011 9:56 pm ]
Post subject:  Re: Detect if there is terrain within a certain range?

Use this: http://wiki.datarealms.com/index.php/Lu ... bstacleRay

Author:  deathbringer [ Sun Jul 17, 2011 10:22 pm ]
Post subject:  Re: Detect if there is terrain within a certain range?

Thanks for your help ^^ But for some reason it gives me an error about wrong arguments when I use it.

I tried doing SceneMan:CastObstacleRay(self.Pos, 100, Vector(0, 0), Vector(0, 0), self.ID, 0, 5);
Is there something I'm missing?

Author:  TheLastBanana [ Sun Jul 17, 2011 11:51 pm ]
Post subject:  Re: Detect if there is terrain within a certain range?

Seems you added an extra argument in there. That 100 shouldn't be there.

Author:  deathbringer [ Mon Jul 18, 2011 12:33 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Wierd... Then where should I write the range of the ray?

Author:  Roast Veg [ Mon Jul 18, 2011 12:34 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

You wouldn't, the ray will keep going until it reaches the edge of the map.

Author:  deathbringer [ Mon Jul 18, 2011 12:36 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Oh. Wont that create some issues with the seam maps?

Edit : It still doesn't work. Same error...

Author:  TheLastBanana [ Mon Jul 18, 2011 12:52 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

The ray doesn't go until the edge of the map, it goes until the end of the vector you specify. In this case, it doesn't go anywhere at all, since your vector is (0,0).
Anyway, is this what you have?
Code:
SceneMan:CastObstacleRay(self.Pos, Vector(0, 0), Vector(0, 0), self.ID, 0, 5)

Author:  deathbringer [ Mon Jul 18, 2011 1:20 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Yes this is exactly what I have and I still get an error in the console saying that the arguments don't match. Is there any way to make it so it checks an area of like 100 pixels around it?

Edit : I get this exactly
Image

Author:  TheLastBanana [ Mon Jul 18, 2011 2:03 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Oh, sorry, you're missing a fourth vector there.
Code:
SceneMan:CastObstacleRay(self.Pos, Vector(0, 0), Vector(0, 0), Vector(0, 0), self.ID, 0, 5)

That shouldn't generate any errors. As for checking a radius, that's not easy to do. If you want the missile to explode just before it hits something, why not just trace along the missile's velocity?

Author:  deathbringer [ Mon Jul 18, 2011 3:25 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Code:
SceneMan:CastObstacleRay(self.Pos, self.Vel*10, Vector(0,0), Vector(0,0), self.ID, 0, 5);

That did the trick, now its working perfectly. Thanks for the pointers :P

Btw, is there any way to fill an array with all the attachments of an object?

Author:  CaveCricket48 [ Mon Jul 18, 2011 7:09 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Code:
   -- self.target = blahblah;
   self.attaTable = {};

   for i = 1, MovableMan:GetMOIDCount()-1 do
      local part = MovableMan:GetMOFromID(i);
      if part.RootID == self.target.ID then
         self.attaTable[#self.attaTable+1] = part;
      end
   end

self.target is the pointer to the object you're looking for attachments, self.attaTable is the array with the attached parts (including the target itself).

Author:  deathbringer [ Mon Jul 18, 2011 7:48 am ]
Post subject:  Re: Detect if there is terrain within a certain range?

Hmm. The loop doesn't seem to be working.

After making a print of the part.rootID it shows a bunch of nil in the console... is this normal?
Nvm but the loop doesn't find any matching IDs. Also the target is "self" and its ID is always 255. (I've reduced the syntax to self.ID instead of self.target.ID as well..)

Author:  TheLastBanana [ Mon Jul 18, 2011 8:20 pm ]
Post subject:  Re: Detect if there is terrain within a certain range?

If I remember correctly, the attachables need GetsHitByMOs set to true in order to be found in the list. It could also be HitsMOs, I forget which.

Author:  deathbringer [ Mon Jul 18, 2011 9:20 pm ]
Post subject:  Re: Detect if there is terrain within a certain range?

Oh, that's probably the problem then. Both values are set to 0... Testing.

Edit : Nope still nothing. The loop still don't find any matching ID. I even put both values to 1 to be sure and no result.

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/