Moving frame that bounces of edges

Hi,
I am trying to make a lockpicking minigame for my game, and what I have in mind is that there’s 6 pins, and first one moves up and down and when it touches the edge of the frame it goes down and when it reaches the bottom it goes up and so on. If you click and the pin is touching the centre line then it stops and pin 2 moves and so on till you either miss it or do all 6 pins.

I know I can do the movement with tween service, but I am stuck on how would I know if the pin touched the edge of the frame and then make it go back.

Gui looks like this:
image
(Pins have random sizes and as you can see move to radnom Y position)

So assuming you’re using Scaled to move those locks here:

0 on the Y axis is the top of the black rounded frame. 1 is the bottom.

Knowing this, you can determine if a lock has reached the bottom by taking into account their size (again I’d use Scaled so it works consistently)

So say a lock’s size is .2 on the Y axis. You’d take the lock’s current Y scaled position, and then add its Y size to that. That’ll give you an accurate position where it is relative to the bottom of your black frame.

Determining if a lock’s touching the center line?

You could use some simple 2D collision logic to determine if any lock is colliding with your line, something similar to:

local function isLockTouchingCenter(lock)
--//Assuming everything uses Scaled (position and size for the lock)
local lockPos, lockSize = lock.Position, lock.Size
local centerPos, centerSize = center.Position, center.Size

if lockPos + lockSize > centerPos and lockPos < centerPos + centerSize then
return true --//The lock is touching the center line
end
end
2 Likes

Since the frame have limited space usually every single part touch the end when the position is Udim2.new(0,0,0,Frame.Size.Offset.y) or Udim2.new(0,0,Frame.Size.Scale.y,0) (depends on which value is used to determine the size) and the other end position is Udim2.new(0,0,1,-Frame.Size.Offset.y) or Udim2.new(0,0,1 - Frame.Size.Scale.y,0)

1 Like

Thank you, I will try that. And yes it’s all scaled but for some reason bottom position is 0 but the top is 0.586.

I’d also parent those locks inside of your black frame if they’re not already, should make this easier to deal with.

1 Like

Thanks, they are parented. Btw how would I do the movement? Would I use tween service or just a while true do loop that moves it and checks if it reached top or bottom and checks if player clicked and if the lock is on the centre line when the click happened.

I am stuck, I don’t understand how would I get the position of the bottom of the frame and of the top.

local function isAtBottom(lock) 
return lock.Position.Y.Scale + lock.Size.Y.Scale  >= 1
end

local function isAtTop(lock)
return lock.Position.Y.Scale <= 0
end

Try these. Should work great if you’re using Scaled for both size and position on everything. Also be sure the locks are parented inside of the black background frame you have.

You can also use this in conjunction with TweenService, just use like a while loop during the duration of the lockpicking.

1 Like

Thank you for helping, I’ve finished it already by checking the position and it works great.

1 Like