Talk:GUI Collision Tutorial: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>SoulStealer9875
No edit summary
>Flurite
No edit summary
 
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:
I don't like where this is going. You shouldn't detect collisions with `.Position`. You should use .AbsolutePosition {{User:NXTBoy/sig|date=22:01, 2 August 2011 (UTC)}}
Possible duplicate of [[Collision_detection_for_GUI's]]<div style="border-top: 1px solid #AAA; color:#000000; font-size:10px">Trappingnoobs <span style="color:skyblue">(Writer)</span><span style="color:red"> Have I done something bad? Good? Tell me on my [[User_talk:Trappingnoobs|talk page]]</span><span style="color:grey;float:right">  15:51, 6 August 2011 (UTC)</span></div>
:That page is terrible{{User:NXTBoy/sig|date=18:41, 6 August 2011 (UTC)}}
::Still, we have two pages for the same thing. :l<div style="border-top: 1px solid #AAA; color:#000000; font-size:10px">Trappingnoobs <span style="color:skyblue">(Writer)</span><span style="color:red"> Have I done something bad? Good? Tell me on my [[User_talk:Trappingnoobs|talk page]]</span><span style="color:grey;float:right">  13:36, 7 August 2011 (UTC)</span></div>


I don't see how this teaches users how to detect when GUIs collide, all it seems to teach is magnitude... <div style="border-top: 1px solid #AAA; color:#000000; font-size:10px">([[User:SoulStealer9875|SoulStealer9875]], [http://www.roblox.com/My/PrivateMessage.aspx?RecipientID=3827581 Send Message], [[Scripting_Book|Scripting Book]], [http://www.roblox.com/User.aspx?username=SoulStealer9875 My Profile])</div>07:59, 3 August 2011 (UTC)
 
:::Sorry, I know what I wrote was terrible. :(
:::Also, how do you add one of those signatures you guys have? (Flurite)
{{outdent|:::}}
Isn't the standard formula for detecting GUIs this?
<pre>
function IsTouching(gui1, gui2)
return gui1.AbsolutePosition.X + math.abs(math.floor(gui1.AbsoluteSize.X)) > gui2.AbsolutePosition.X and
gui2.AbsolutePosition.X + math.abs(math.floor(gui2.AbsoluteSize.X)) > gui1.AbsolutePosition.X and
gui1.AbsolutePosition.Y + math.abs(math.floor(gui1.AbsoluteSize.Y)) > gui2.AbsolutePosition.Y and
gui2.AbsolutePosition.Y + math.abs(math.floor(gui2.AbsoluteSize.Y)) > gui1.AbsolutePosition.Y
end
</pre>
 
{{User:flurite/signature|date=21:36, 21 January 2012 (UTC)}}
:That's a real mess, and impossible to read. Why the {{`|math.abs(math.floor(}}? {{User:NXTBoy/sig|date=22:21, 21 January 2012 (UTC)}}
::Well, that's how I was taught and it seems pretty common elsewhere as well. The math.floor() was used because sometimes the size of a UDim2 gets to a decimal point for some reason, so that rounds it down to the nearest pixel, and the math.abs() is used for negative positions. What's good about using AbsolutePositions/Sizes is that they work for scales and offsets and a combination. With explanation and diagrams, it's pretty easy to understand. {{User:flurite/signature|date=01:00, 22 January 2012 (UTC)}}
::: ''the math.abs() is used for negative positions'' - Read your code again - it's being used on AbsoluteSize. Surely that's always positive? {{User:NXTBoy/sig|date=08:50, 22 January 2012 (UTC)}}
:::: Oh, well I guess that might not matter, but share that formula on the wiki? {{User:flurite/signature|date=16:11, 22 January 2012 (UTC)}}

Latest revision as of 16:11, 22 January 2012

Possible duplicate of Collision_detection_for_GUI's

Trappingnoobs (Writer) Have I done something bad? Good? Tell me on my talk page 15:51, 6 August 2011 (UTC)
That page is terrible
18:41, 6 August 2011 (UTC)
Still, we have two pages for the same thing. :l
Trappingnoobs (Writer) Have I done something bad? Good? Tell me on my talk page 13:36, 7 August 2011 (UTC)


Sorry, I know what I wrote was terrible. :(
Also, how do you add one of those signatures you guys have? (Flurite)

Isn't the standard formula for detecting GUIs this?

function IsTouching(gui1, gui2)
	return gui1.AbsolutePosition.X + math.abs(math.floor(gui1.AbsoluteSize.X)) > gui2.AbsolutePosition.X and
	gui2.AbsolutePosition.X + math.abs(math.floor(gui2.AbsoluteSize.X)) > gui1.AbsolutePosition.X and
	gui1.AbsolutePosition.Y + math.abs(math.floor(gui1.AbsoluteSize.Y)) > gui2.AbsolutePosition.Y and
	gui2.AbsolutePosition.Y + math.abs(math.floor(gui2.AbsoluteSize.Y)) > gui1.AbsolutePosition.Y
end

Flurite - 21:36, 21 January 2012 (UTC)

That's a real mess, and impossible to read. Why the math.abs(math.floor(?
22:21, 21 January 2012 (UTC)
Well, that's how I was taught and it seems pretty common elsewhere as well. The math.floor() was used because sometimes the size of a UDim2 gets to a decimal point for some reason, so that rounds it down to the nearest pixel, and the math.abs() is used for negative positions. What's good about using AbsolutePositions/Sizes is that they work for scales and offsets and a combination. With explanation and diagrams, it's pretty easy to understand. Flurite - 01:00, 22 January 2012 (UTC)
the math.abs() is used for negative positions - Read your code again - it's being used on AbsoluteSize. Surely that's always positive?
08:50, 22 January 2012 (UTC)
Oh, well I guess that might not matter, but share that formula on the wiki? Flurite - 16:11, 22 January 2012 (UTC)