Jump to content

Recommended Posts

Posted

I have a vec3 position and I have a zone. I am looking for a function that will tell me if that point is in the zone or not. I use mist but do not see a comparable function. I have tried the mist.utils.get3DDist but am getting a 3627: attempt to index local 'point1' (a nil value) error even though when I display both points, they seem valid (both have the required y,x,z values).

 

Thank you.

Posted

I think you'd need to use the vec3 point you have and the centre co-ords of the zone and then determine the distance between the two points using mist.utils.get3DDist and then if the distance is less or equal to the radius of the zone the vec3 point is inside the zone. trigger.misc.getZone(zonename) will give you the vec3 co-ordinates for the zone centre I believe.

Posted

Yeah, thats what I tried to do, but the mist function is giving me an error. I decided to do the math directly with the point information I have and that worked. Seems I am somehow passing the wrong values to the mist function or something, but anyways, I got it working.

 

Thanks

 

 

			local u = event.initiator
		local name = u:getName()
		local uLoc = u:getPoint()
		local inflight = u:inAir()
	
		for n = 1, #WWIIC_data.oob.red.squadron do
			if string.find(name, WWIIC_data.oob.red.squadron[n].unit) ~= nil then								--find squadron of unit (unit name is part of squadron name)
				local uZone = trigger.misc.getZone('Axis_Recovery_zone')
				local xd = uZone.point.x-uLoc.x
				local zd = uZone.point.z-uLoc.z
				uDistance = (xd^2 + zd^2)^0.5
				break
			end
		end	

 

Posted
I think you'd need to use the vec3 point you have and the centre co-ords of the zone and then determine the distance between the two points using mist.utils.get3DDist and then if the distance is less or equal to the radius of the zone the vec3 point is inside the zone. trigger.misc.getZone(zonename) will give you the vec3 co-ordinates for the zone centre I believe.

 

Mostly correct except for two things. You need to use trigger.misc.getZone(zoneName).point because the table returned isn't strictly a vec3 table. Also mist.utils.get3DDist is comparing the distance to a sphere while mist.utils.get2DDist is a cylinder with effectively infinite height. So if you used the get3DDist and were at an altitude higher than the radius of the zone, then the distance from the center would be greater than the radius.

 

 

More to the point its just a basic Pythagorean theory in practice. if (A^2 + B^2)^.5 < radius. Here is a sample from my iadscript. Its trying to find the nearest target the the sam site. If the distance is closer than the current closed target, then it replaces what the closes target is.

 

for unitId, unitData in pairs(iad_targets) do
if Unit.getByName(unitData.unitName) and unitData.coalition ~= iadGroup.coalition  then
	if math.sqrt((pos.x - unitData.pos.x)^2 + (pos.z - unitData.pos.z)^2) < nearDist then
		nearest = unitData.unitName
		nearDist = math.sqrt((pos.x - unitData.pos.x)^2 + (pos.z - unitData.pos.z)^2)
	end
end
end

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...