I am lost so help would be appreciated. I have a ImageLabel you can move around, and acts as a person. And it checks if they are touching this other image that they should not be able to go through. That all works, but if they touch the GUI they cannot move around at all. I want them to be able to run into the image, then be able to move after, although, I am lost on the math.
Here is the function I am using:
function checkPosition(gui1, gui2)
local gui1_topLeft = gui1.AbsolutePosition
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y))
end
And I'm sure this will change based on the movement key. (There are 4 scripts each for a different key.)
Here is my full script if anybody needs it (Again, there are 4 copies of this script that are mostly the same) :
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local keydown = false
function checkPosition(gui1, gui2) ---A little different wording but it serves the same purpose
local gui1_topLeft = gui1.AbsolutePosition
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y))
end
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.A then
keydown = true
end
end)
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.A then
keydown = false
end
end)
while true do
wait()
if keydown then
if script.Parent.Parent.Floor.AbsolutePosition.X > 632 then
--Detects if they went off the frame
else
if checkPosition(script.Parent, script.Parent.Parent.Counter) == false then --It returns true if they are touching, but I only want it to return true if they are trying to go into the image.
script.Parent.Position = script.Parent.Position - UDim2.new(0.005,0,0,0)
end
end
end
end
So again what I need help with is the math on the function, so they cannot go into the image, but away from it after they hit it. Yes, I am aware that the math will be different depending on the key, so if somebody can help explain what I do to get the right equation. Thanks, Jail!
