I DO NOT WANT A SCRIPT FOR THIS. I just want a concept of how to do it. I already sto-- I mean borrowed Merely's function for this (I definitely could have made my own, I just didn't feel like it). Setting the object's position when it collides back to the previous position is really just no. It does not work well with momentum. I tried using collision vectors but that didn't work and is probably pretty clunky. I am using AABB collision so maybe I should try using raycasting? But I feel like that will have its own problems.
Here is my function (slightly modified). Ignore the bad tab indentation (it's already tabbed)
collides = function(self, gui2, needsVector) local gui1 = self.reference -- The first gui object. I am using self here because I'm using it everywhere right now. local gui1_topLeft = gui1.AbsolutePosition local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize local gui2_topLeft = gui2.AbsolutePosition local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize local collisionVector if needsVector then if (gui1_topLeft.X < gui2_bottomRight.X) and (gui1_topLeft.Y < gui2_bottomRight.Y and gui1_bottomRight.Y > gui2_topLeft.Y) then collisionVector = Vector2.new(-1, 0) elseif (gui1_bottomRight.X > gui2_topLeft.X) and (gui1_topLeft.Y < gui2_bottomRight.Y and gui1_bottomRight.Y > gui2_topLeft.Y) then collisionVector = Vector2.new(1, 0) elseif (gui1_topLeft.X < gui2_bottomRight.X and gui1_bottomRight.X > gui2_topLeft.X) and (gui1_topLeft.Y < gui2_bottomRight.Y) then collisionVector = Vector2.new(0, -1) elseif (gui1_topLeft.X < gui2_bottomRight.X and gui1_bottomRight.X > gui2_topLeft.X) and (gui1_bottomRight.Y > gui2_topLeft.Y) then collisionVector = Vector2.new(0, 1) end end 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)), collisionVector end
(Really inefficient and I will clean this up later)
A problem is when I collide with a object it will just default to this first if in needsVector
because it's inside the object already so the first if is true automatically.
Raycasting would seem to fix this but then I would need a bunch of other stuff and I just want a way to do collisions (not just detect that is easy) without jittery movement.
I know this is probably really difficult and maybe I should just use Unity because it already has 2D tools but I would like to make a pure GUI game in ROBLOX.
I'm really just looking for an efficient and good looking to the player method of GUI collision (I have never done collision before)