Jump to content

Checking for valid tile ?


Recommended Posts

Hi,

I have a working code doing what i want, except one point : it is supposed to spawn a prefab somewhere in the world, and this part works, but the prefab could spawn in tiles players aren't supposed to reach. Here is the code :


	local pt = Vector3(math.random(-1000, 1000), 0, math.random(-1000, 1000))
	local tile = TheWorld.Map:GetTileAtPoint(pt.x, pt.y, pt.z)    
		local myprefab = SpawnPrefab("myprefab")
		myprefab.Transform:SetPosition(pt:Get())
		print("Prefab spawned")

Usually i use a variant of this code :

		local pt = Vector3(math.random(-1000, 1000), 0, math.random(-1000, 1000))
		local tile = TheWorld.Map:GetTileAtPoint(pt.x, pt.y, pt.z)    
		if tile == GROUND.DECIDUOUS then
			local myprefab = SpawnPrefab("myprefab")
			myprefab.Transform:SetPosition(pt:Get())
			print("Prefab spawned")
		end

But in this case i don't want to spawn it on a specific ground, only on "valid" ground (don't care which one)

 

What is the best way to do it ?

 

Edit : maybe found something with "~= GROUND.IMPASSABLE", will do some tests.

Edited by Lumina
Link to comment
Share on other sites

Probably, I don't remember exactly all the GROUND table's member.

You have the complete list in constants.lua

You probably want to avoid GROUND.FAKE_GROUND also, whatever it is (it did not exist last time I was modding)

Edited by ZupaleX
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...