View unanswered posts | View active topics It is currently Tue Jul 23, 2019 6:14 am



Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
 Detect if there is terrain within a certain range? 
Author Message
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Detect if there is terrain within a certain range?
Use this: http://wiki.datarealms.com/index.php/Lu ... bstacleRay


Sun Jul 17, 2011 9:56 pm
Profile
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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
Profile
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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


Mon Jul 18, 2011 1:20 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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?


Mon Jul 18, 2011 3:25 am
Profile
Online
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 11426
Location: Here
Reply with quote
Post 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
Profile
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Dec 21, 2008 8:16 am
Posts: 293
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 19 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.020s | 13 Queries | GZIP : Off ]