my game working - YouTube before i changed it
my game breaks - YouTube after i changed it
I didnt know what to search on devforum to fix this so i just made a new post
the problem is that the game works completely fine when the camera only goes left and right. but it annoyed me that when my character was out of frame i couldnt see it, so i made the camera go up and down too, but for some reason that caused the blocks to noclip and stick onto each other
heres some of the code from my script
for _,obj:GuiObject in pairs(getObjects()) do
if obj:GetAttribute("Anchored") == false then
local velocityX = obj:GetAttribute("VelocityX")
local velocityY = obj:GetAttribute("VelocityY")
local newpos
local touchedObj = touching(obj)
if touchedObj then
local bounce = true
velocityY = -(velocityY / 2)
if bounce and velocityY <= 0 then
obj:SetAttribute("VelocityY", math.round(velocityY))
else
velocityY = 0
end
newpos = obj.Position + UDim2.fromOffset(0, velocityY)
else
velocityY = velocityY + (script:GetAttribute("Gravity")/100)
obj:SetAttribute("VelocityY", velocityY)
newpos = obj.Position + UDim2.fromOffset(0, velocityY)
end
local posTouchedobj = touchingPos(newpos, obj)
if touchedObj then
if newpos.Y.Offset >= (touchedObj.AbsolutePosition.Y - obj.AbsoluteSize.Y) and newpos.Y.Offset <= (touchedObj.AbsolutePosition.Y) then
obj.Position = UDim2.fromOffset(obj.Position.X.Offset, (touchedObj.AbsolutePosition.Y - obj.AbsoluteSize.Y))
end
else
obj.Position = newpos
end
if velocityX < 0 then
velocityX = velocityX + (script:GetAttribute("Gravity")/200)
elseif velocityX > 0 then
velocityX = velocityX - (script:GetAttribute("Gravity")/200)
end
obj:SetAttribute("VelocityX", velocityX)
obj.Position = obj.Position + UDim2.fromOffset(velocityX, 0)
elseif obj:GetAttribute("Type") == "Player" and obj ~= Player then
-- Nothing
end
end