Data Realms Fan Forums
http://forums.datarealms.com/

Determining whether something is underground
http://forums.datarealms.com/viewtopic.php?f=73&t=31705
Page 1 of 1

Author:  Djinn [ Wed Sep 19, 2012 5:12 am ]
Post subject:  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?

Author:  Abdul Alhazred [ Wed Sep 19, 2012 9:53 am ]
Post subject:  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.

Author:  p3lb0x [ Wed Sep 19, 2012 1:22 pm ]
Post subject:  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.

Author:  Technomancer [ Wed Sep 19, 2012 8:30 pm ]
Post subject:  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..

Author:  zalo [ Sat Sep 29, 2012 4:48 am ]
Post subject:  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.

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