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: How do i a collision detection?

Previous Thread :: Next Thread 
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 07:20 AM
I was thinking of making a function wich i can pass the surfaces/edges/corners of an object and it returns me the points of collision and optionally depth.

How is it done usually?

If im going to use it ill use it to check point of collision for roblox objects, wich means itll usually just be a box-box collision, but i guess i need to add a special function for spheres and use that with cylinders too because cylinders seem to be spheres -.-


Do i just check for surface-edge collisions for normal parts, and for spheres i would check corners, edges and surfaces against the sphere?
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
12 Nov 2011 07:25 AM
Maybe use regions?
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 07:28 AM
No theyre inflexible. They must be.


I dont actually need this, but i wanna know in case i bother to make the function :P
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
12 Nov 2011 10:17 AM
Maybe a ray going from the brick it hit into the other one, then you would get the center point of where it hit.

Like so.

script.Parent.Touched:connect(function (hit)
local myPos = script.Parent.Position
local youPos = hit.Position
local _,hitPos = game.Workspace:FindPartOnRay(Ray.new(myPos,CFrame.new(myPos,youpos).lookVector*10),script.Parent)
--hitPos beh the center of where the part hit :D
end)

Something like that?
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 10:36 AM
@above

No that fails. I want to know where the parts hit, not some random point thats sometimes located on one of the surfaces facing the other part o,e


Kitten Engine has too many functions i dont remember half of them and out of the ones i do remember i dont remember what arguments they want -.-
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
12 Nov 2011 10:37 AM
Oh yeah, that gets the surface, my bad.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 10:38 AM
^^^^

POTENTIALLY gets the surface.
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
12 Nov 2011 10:38 AM
Looking at it, from a 3D perspective, that should definetly get the surface, maybe I'm just being stupid.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 10:49 AM
@combrad

Huge long stick with a huge long stick thats on top of first stick with one end.


liek
|_ (top-down)


if you raycast to center of other stick it gets the wrong surface. At least if the other stick is also tall.
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
12 Nov 2011 10:50 AM
Oh, yes, I see, thank you for clearing that up.
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 11:21 AM
If a projectile were hitting a brick...
To check for surface...

I would raycast from the protruding corner/edge of the projectile in the direction of its velocity.

That would hit the surface of the brick
then

relativehitpoint = brick.CFrame:pointToObjectSpace(hitpoint)

if math.abs(relativehitpoint.X) < brick.Size.X/2 and math.abs(relativehitpoint.Y) < brick.Size.Y/2 and math.abs(relativehitpoint.Z) < brick.Size.Z/2 then

if relativehitpoint.Z<0 then surface = "Back" end
if relativehitpoint.Z>0 then surface = "Front" end

end

then do that for the other 4 surfaces

if you get what i'm trying to do.





for spheres...

I can only think of... you define a plane which both the center of the sphere and the protruding end of the projectile lie in. In that plane you'll have a circle that is the cross section of the sphere and a weird polygon that is the cross section of the projectile, if it is a box. Then you do intersection between lines of the polygon and the circle.
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 11:22 AM
edit:


it should be

if math.abs(relativehitpoint.X) < brick.Size.X/2 and math.abs(relativehitpoint.Y) < brick.Size.Y/2 and math.abs(relativehitpoint.Z) >= brick.Size.Z/2 then

...
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 11:39 AM
No u collision detection doesnt use raycasting cuz it lags.

You just check for intersections between edges and surfaces n stuff.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
12 Nov 2011 12:47 PM
Use separating axis theorem. That states that if you can find an axis on which the parts are separated, then the parts are not colliding. And if there is overlap on all axis, the axis with the most overlap is the one you should separate the parts on.

Here's a really good tutorial with lots of demos which shows you how it works:
http://www.metanetsoftware.com/technique/tutorialA.html
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 01:41 PM
Interesting. But with 3D objects, you're finding a "separating plane" where the 2D projections of the 3D objects don't intersect. But to check whether the 2D projections intersect requires finding another separating axis. And you have to do that for each 2D projection of the objects you test.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
12 Nov 2011 02:05 PM
BUT WAT IF ITS A NOT-CONVEXZ??? :C
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 02:19 PM
You divide it into convex pieces?
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
12 Nov 2011 02:53 PM
@gyz
It's still a separating axis in 3D, clearly you didn't actually read about it before posting. Yes, there is a plane which doesn't touch either thing, but there is still a separating axis perpendicular to that plane.

"BUT WAT IF ITS A NOT-CONVEXZ??? :C"
Then you break it into "convex hulls". That's how pretty much all engines do collision detection, breaking collision shapes into convex hulls and doing collision detection on each of those separately.
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 04:07 PM
No I perfectly know what I'm talking about. Yes, I did read it and play around with the diagrams.

There are two ways to do it in 3D. You can (1) define a plane between the objects through which both objects do not intersect. (which is what I believe you are intending, and while it uses the idea of the theorem, it doesn't exactly follow its steps) or (2) define a axis which specifies the plane onto which you project 2D silhouettes/outlines of the shapes, then apply separating axis theorem on the 2D outlines.


Read Wikipedia article also? In 3D its called the separating plane theorem. I'm pretty sure that the "plane" is referring to what the 3D shapes are projected onto, and in 2D, the "axis" is referring to the line that the 2D shapes are projected onto.

Just like in the demonstrations of the website you linked to, the 2D shapes are projected onto the separating axis(es) as 1D lines, and if they don't overlap, the shapes don't collide. So in 3D, the 3D shapes are projected onto the separating plane(s) as 2D shapes, and if they don't overlap, they don't collide.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
12 Nov 2011 04:13 PM
"In 3D its called the separating plane theorem. I'm pretty sure that the "plane" is referring to what the 3D shapes are projected onto, and in 2D, the "axis" is referring to the line that the 2D shapes are projected onto."

You're incorrect, even in 3D the shapes are still projected onto a line, not onto a plane. After all, why would you want to project the shapes into a plane? Then you would just have to do separating axis theorem _again_ in order to find if they intersect on that plane! (Also, consider: How you you find the plane to project the shapes onto? The separating axis is found by taking an axis which is normal to the surface in 3D or edge in 2D of the shape, and passes though the center of the shape)

http://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Separating_axis_theorem2008.png/220px-Separating_axis_theorem2008.png

If that image from the wiki page is to be believed I am correct even in terminology, and there would still be a "separating axis" in 3D, although you would have a "separating pane" instead of a "separating line".

Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 04:54 PM
"After all, why would you want to project the shapes into a plane? Then you would just have to do separating axis theorem _again_ in order to find if they intersect on that plane!"


That is exactly my point. No matter what happens, you must apply separating plane then separating line.

The other way to describe it... it's a separating plane, and there is a separating axisplane that is perpendicular to that.

The only way you can check that a separating plane truly separates the two shapes is by looking down the plane (as if you were looking right on at the edge of piece of paper so it appears to be a flat line). As with the paper, by placing your line of sight down the separating plane, the plane now appears to be a separating line. The shapes appear 2D, as they are projected so onto your eyes. (a)

Also, I know that you can use a line to define the plane that is perpendicular to it, but there is no way to project an entire 3D shape onto a line. You can only project a cross section of that shape onto a line, and the cross section lies on a 2D plane that you have to define. (b)
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 04:55 PM

Either way you look at it, the 3D gets converted into something similar to the 2D image shown in the wiki page.

(a) In one way, the image you are seeing is the separating axisplane. The shapes are projections onto the separating axisplane, the separating axis is a line you define on the axisplane. The separating line is defined by the intersection of the separating plane and the separating axisplane, which are perpendicular.

(b) For the other way, the image you are seeing is the plane on which the cross sections of the 3D shapes lie on. The 2D shapes are cross sections. The separating line is the intersection between the cross section plane and the separating plane. The separating axis in 2D is the same as the separating axis in 3D, but in 2D the line cuts the entire dimension in half (so you can project onto it), whereas in 3D its just a line.

For (b), you have to do multiple cross sections because cross section may not go through the widest part of the object.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
12 Nov 2011 05:11 PM
"Also, I know that you can use a line to define the plane that is perpendicular to it, but there is no way to project an entire 3D shape onto a line."

That's totally wrong. It's just as easy to project a 3D solid onto a line as it is to project a 2D shape onto a line.. In fact, it's the _exact same_ code semantically:

for surface in shape.surfaces do
local axis = surface.normal
local min, max = math.inf, 0
for point in shape.points do
local d = (point-axis.origin):dot(axis.direction)
if d > max then max = d end
if d < min then min = d end
end
end

That gives you the min/max lengths along the separating axis in any arbitrary number of dimensions. The number of dimensions of "point" will just be different for each number of dimensions, but you can still project it onto an axis defined by two such points just as well with dot product.
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 05:27 PM
oops, in math, you would project 2D first, but here you can just squish the shape into a line, then find the ends of that line.
Technically if the line was the x axis, its just ignoring the y and z values of the shape.
Report Abuse
gyz is not online. gyz
Joined: 27 Aug 2008
Total Posts: 741
12 Nov 2011 05:28 PM
Well anyways, i understand what you're getting at.
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