Author |
Message |
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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.
|
Sun Jul 17, 2011 9:28 pm |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
Re: Detect if there is terrain within a certain range?
|
Sun Jul 17, 2011 9:56 pm |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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?
|
Sun Jul 17, 2011 10:22 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Detect if there is terrain within a certain range?
Seems you added an extra argument in there. That 100 shouldn't be there.
|
Sun Jul 17, 2011 11:51 pm |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
Re: Detect if there is terrain within a certain range?
Wierd... Then where should I write the range of the ray?
|
Mon Jul 18, 2011 12:33 am |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
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.
Last edited by Roast Veg on Mon Jul 18, 2011 1:08 am, edited 1 time in total.
|
Mon Jul 18, 2011 12:34 am |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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...
|
Mon Jul 18, 2011 12:36 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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)
|
Mon Jul 18, 2011 12:52 am |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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
|
Mon Jul 18, 2011 1:20 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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?
|
Mon Jul 18, 2011 2:03 am |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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 Btw, is there any way to fill an array with all the attachments of an object?
|
Mon Jul 18, 2011 3:25 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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).
|
Mon Jul 18, 2011 7:09 am |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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..)
|
Mon Jul 18, 2011 7:48 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Mon Jul 18, 2011 8:20 pm |
|
|
deathbringer
Joined: Sun Dec 21, 2008 8:16 am Posts: 293
|
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.
|
Mon Jul 18, 2011 9:20 pm |
|
|
|