View unanswered posts | View active topics It is currently Wed Dec 25, 2024 5:39 pm



Reply to topic  [ 5 posts ] 
 Determining whether something is underground 
Author Message
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Determining whether something is underground
More questions! Is there a way you can tell whether something's underground or not? I know Zalo's diggerator had something to check that, but I cannot make hide or tails of it and it also doesn't work in this version. Any ideas?


Wed Sep 19, 2012 5:12 am
Profile YIM
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Determining whether something is underground
You can cast a ray upwards, and if it collides with terrain the point you cast the ray from is probably under ground.


Wed Sep 19, 2012 9:53 am
Profile
Forum Moderator
User avatar

Joined: Fri Feb 02, 2007 3:53 pm
Posts: 1896
Location: in my little gay bunker
Reply with quote
Post Re: Determining whether something is underground
Alternatively, you could cast a fan of 3 or so rays to avoid hitting a single piece of debris or seeing if a character is standing in a doorway. However, I am not sure if this would too computationally intensive for too little gain.


Wed Sep 19, 2012 1:22 pm
Profile
User avatar

Joined: Sat Jul 31, 2010 10:01 pm
Posts: 42
Reply with quote
Post Re: Determining whether something is underground
If you wanted to find if something just doesn't have line of sight to the air as a way of measuring "underground-ness", theoretically you could also do something like

Code:
if SceneMan:CastStrengthSumRay(self.Pos,SceneMan:MovePointToGround(Vector(self.Pos.X,0),1,1),0,128) >= 5 then
  --You are under at least 5 strength units worth of terrain (admittedly not much, you could adjust that), do stuff
else
  --You are under only a small bit of scrap or nothing, aka above ground, do other stuff
end


Haven't tested it, but this would likely work with overhangs and/or tall ceilings. Would still have the issue of only being a single ray and therefore not noting if you're in say a doorway.
Would also probably be terrible for deep levels, so you might want to do something like this instead:

Code:
local foundGround = SceneMan:MovePointToGround(Vector(self.Pos.X,0,1);
if SceneMan:GetShortestDistance(self.Pos,foundGround,false) > 800 then
   if SceneMan:CastStrengthSumRay(self.Pos,foundGround,1,1),0,128) >= 5 then
      --You are under at least 5 strength units worth of terrain (admittedly not much, you could adjust that), do stuff
   else
      --You are under only a small bit of scrap or nothing, aka above ground, do other stuff
   end
else
   --Use one of the other ways to check if underground I guess, or maybe do a check not from the sky (so you'd do SceneMan:MovePointToGround(Vector(self.Pos.X,math.min(self.Pos.Y + 500,SceneMan.SceneHeight/2),1) or something like that)
end


Maybe this is overcomplicating things though..


Wed Sep 19, 2012 8:30 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Determining whether something is underground
For future lua explorers:
Code:
SceneMan:FindAltitude(Pos, 0,0);

Returns offset in relation to highest piece of terrain at Pos.


Sat Sep 29, 2012 4:48 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

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.036s | 13 Queries | GZIP : Off ]