generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is there anyway to determine if two parts overlap?

Previous Thread :: Next Thread 
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
14 Jan 2016 11:23 PM
What I mean by this is in the same that they clip through each other. I'm sure I could use some raycasting if need be but if there's a better option I'm all for hearing it.
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
14 Jan 2016 11:26 PM
You could try looking into clipping algorithms. They might give you a much more accurate representation than raycasting.
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
14 Jan 2016 11:27 PM
This I guess?

http://wiki.roblox.com/index.php?title=API:Class/BasePart/GetTouchingParts
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
14 Jan 2016 11:33 PM
Wow I never knew that existed. Incredibly useful; Thanks!
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
14 Jan 2016 11:35 PM
@LongKill

Unfortunately I need something more flexible than this. It returns a group of parts but what I'm really looking for is a function that lets me input a Vector3 (even if it's not necessarily tied to a part) and see if it would be overlapping with the confines of the other part.



This game is only utilizing two vectors so the idea for raycasting would be to shoot a ray half the length of the part's size in four directions. If it hits anything then obviously something's clipping it.
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
14 Jan 2016 11:38 PM
Hm; I suppose you could construct a region3 in the 'box' area where you want to check for collisions, and use FindPartsInRegion3() to get a table of everything inside the region.

However, it can't return more than 100 parts, and this might not be what you want anyway. I have no other suggestions.
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
14 Jan 2016 11:41 PM
@Long

I think this could work actually. Each time I'd be using this it'd only be searching for a couple parts at a time max anyway. Thanks for the help!
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
14 Jan 2016 11:47 PM
Region3 wouldn't really work for huge parts

this is a simple idea that first came to my mind
basically you just position a part using position, then check if it moves or not

no, I have never tried it and don't know what problems it could cause
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
14 Jan 2016 11:53 PM
"Region3 wouldn't really work for huge parts"

idk y i just said that

it's probably incoorect

school->
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
15 Jan 2016 12:28 AM
I can't seem to get FindPartsInRegion3 to work even when there are parts within the region.

Here's my code:


while true do
wait(1)

point1 = Vector3.new(-100, 0, 100)
point2 = Vector3.new(0, 100, -100)
region = Region3.new(point1, point2)
for _,Part in pairs(workspace:FindPartsInRegion3(region,nil,100)) do
print(Part.name)
end
end



I've screwed around with a few different positions that SHOULD work but nothing shows up in the output. Am I not outputting the results correctly or something?
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
15 Jan 2016 06:23 AM
Bump for help. I got it to work when using a fairly large region for some reason, but not with these smaller regions that I want to use.
Report Abuse
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
15 Jan 2016 06:37 AM
local function IsOverlap(Checktype)
if Checktype:IsA("Vector3") then
local Region = Region3.new(Checktype, Checktype
local FoundCollisions = workspace:FindPartsInRegion3(Region, true, 100)

return FoundCollisions
elseif Checktype:IsA("Part") then
return Checktype:GetTouchingParts()
else
error("Not a valid token type for an overlap check: " ... Checktype)
end
end
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
15 Jan 2016 06:43 AM
" ... Checktype

" ...

...



#code R+ | local RAP = "391,570"; local robux = "R$79,341"
Report Abuse
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
15 Jan 2016 06:45 AM
What is the issue abs
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Jan 2016 06:46 AM
You could use region3. Or you could just get the touching part like before, but instead get it's position + size and work out if it's inside the brick that way which would be easy.

Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
15 Jan 2016 07:32 AM
:GetTouchingParts()

Check out the wiki page on it, it's fairly self-explanatory.
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
15 Jan 2016 07:36 AM
function overlap(p1,p2)

local p1_pos=p1.Position
local p2_pos=p2.Position
return (p1_pos-p2_pos).magnitude<3
end
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
15 Jan 2016 07:51 AM
It appears I've found why FindPartsInRegion3 was not returning anything in some scenarios, even if an object was there.


FindPartsInRegion3 will only work if the two points in the region parameter are in a certain order. The mathematically "bigger" one needs to be second.
Report Abuse
rvox is not online. rvox
Joined: 18 Feb 2011
Total Posts: 5380
15 Jan 2016 08:23 AM
dont unnecessarily use region3

function pointInPart(point,part)
local p1 = part.Position+part.Size/2
local p2 = part.Position-part.Size/2

return point.x <= p1.x and point.x >= p2.x and point.y <= p1.y and point.y >= p2.y and point.z <= p1.y and point.z >=p2.z
end
Report Abuse
nox7 is not online. nox7
Joined: 29 Aug 2008
Total Posts: 27467
15 Jan 2016 08:25 AM
@rvox

That doesn't work nicely if a part is rotated. A solution is as follows:

function pointInPart(point, part)
local p = part.CFrame:pointToObjectSpace(point);
return (math.abs(p.x) <= part.Size.x / 2 and math.abs(p.y) <= part.Size.y / 2 and math.abs(p.z) <= part.Size.z / 2);
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image