I’m working on a mini horse race game using UI elements, and I need to calculate the winner with high precision. Initially, I did this on the server by checking if the frames were touching each other using their absolute position and size, but I was tweening everything on the server, which caused lag. To solve this, I decided to send the X position of the horses from the server to the client, which helped reduce the lag. However, there’s a problem now: since I moved the animations to the client, it became harder to determine if the frames are touching. I thought about creating invisible frames with the exact size of the original ones and comparing their absolute positions, but this solution feels inefficient.
Also, I need to clarify some important things. The frames I want to compare are not in the same frame. To be more specific, I’ll explain the way I was doing before. There are two frames parented to a main frame: HorseFrame (which haves all the horses) and BackgroundFrame (which haves the finish line). Both BackgroundFrame and HorseFrame are animated. If the horses were in the same frame, I could easily compare the scale values, but since they’re not, I had to compare the absolute positions and sizes. Here’s the code I used:
function RaceLogic.IsFrameTouching(frame1, frame2)
local abs1Pos = frame1.AbsolutePosition
local abs1Size = frame1.AbsoluteSize
local abs2Pos = frame2.AbsolutePosition
local abs2Size = frame2.AbsoluteSize
local xOverlap = abs1Pos.X < abs2Pos.X + abs2Size.X and
abs1Pos.X + abs1Size.X > abs2Pos.X
local yOverlap = abs1Pos.Y < abs2Pos.Y + abs2Size.Y and
abs1Pos.Y + abs1Size.Y > abs2Pos.Y
return xOverlap and yOverlap
end
This worked fine until I decided to do animations on client (the best decision I made). Everything I could think of was trying to simulate the AbsolutePosition and AbsoluteSize. So, any suggestions?