Jump to content

Determine whether there is an obstacle between two elements


xyzii

Recommended Posts

Before you even mention it, I know of processLineOfSight and isLineOfSightClear. But those don't fix my issues as far as I'm aware. The two elements would be players and the obstacle is a custom element with no collision. On top of the element is a col shape though. I made a picture to show what I mean if you don't understand;irV9ztm.png

I want to get something like this:

	if (element is in middle of those two players) then
	       -- Do stuff
	end
	

 

Link to comment
  • Moderators
local getDistanceBetweenPointAndSegment3D = function (pointX, pointY, pointZ, x1, y1, z1, x2, y2, z2)

	local A = pointX - x1 
	local B = pointY - y1
	local C = pointZ - z1
	--

	local D = x2 - x1
	local E = y2 - y1
	local F = z2 - z1
	--
	local point = A * D + B * E + C * F
	local lenSquare = D * D + E * E + F * F
	local parameter = point / lenSquare
 
	local shortestX
	local shortestY
	local shortestZ
 
	if parameter < 0 then
		shortestX = x1
    	shortestY = y1
		shortestZ = z1
	elseif parameter > 1 then
		shortestX = x2
		shortestY = y2
		shortestZ = z2

	else
		shortestX = x1 + parameter * D
		shortestY = y1 + parameter * E
		shortestZ = z1 + parameter * F
	end

	local distance = getDistanceBetweenPoints3D(pointX, pointY,pointZ, shortestX, shortestY,shortestZ)
	--
 
	return distance
end

3D version of this one: https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPointAndSegment2D

 

Useful for detecting if something is between 2 points.

 

Edited by IIYAMA
  • Like 2
Link to comment

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
  • Recently Browsing   0 members

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