How do i make the collision applies as the screen is scroling

What do i want to achieve?
I made a boundary just like SMB1.

Just a platformer you know jump and run… with no collision issues

As the screen scrolls the collision must applied to them, but the collision dosen’t apply. how can i fix this?

Code:

GameRender = game:GetService("RunService")
UIS,CAS = game:GetService("UserInputService"),game:GetService("ContextActionService")
LPlayer = game:GetService("Players").LocalPlayer
Camera = workspace.CurrentCamera
Char = LPlayer.Character or LPlayer.CharacterAdded:Wait()
PlayerHitbox =script.Parent.Player
GameFrames = script.Parent.Interacts
Humanoid = Char:WaitForChild("Humanoid")
local left,right,IsJumping,YBasedVelocity,runspeed = false,false,false,0,1 -- 1 is normal speed
local IsFalling,CurrentJumpHeight = false,0
local WallCollison
local thisobject,inboundary = nil,false
Humanoid.WalkSpeed = 0
script.Parent.BGMusic:Play()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.BaseTarget.CFrame

function CheckLeft(ActionName,Bind,Key)
	if Bind == Enum.UserInputState.Begin then
		left = true
	elseif Bind == Enum.UserInputState.End then
		left = false
	end
end

function CheckRight(ActionName,Bind,Key)
	if Bind == Enum.UserInputState.Begin then
		right = true
	elseif Bind == Enum.UserInputState.End then
		right = false
	end
end

function Run(ActionName,Bind,Key)
	if Bind == Enum.UserInputState.Begin then
		runspeed = 4
	elseif Bind == Enum.UserInputState.End then
		runspeed = 1
	end
end



function GoLeft()
	local collision = false
	local Platform = GameFrames:GetChildren()
	for index,object in pairs(Platform) do
		if
			object.Position.X.Scale + object.Size.X.Scale > PlayerHitbox.Position.X.Scale and
			object.Position.X.Scale + object.Size.X.Scale < PlayerHitbox.Position.X.Scale + (PlayerHitbox.Size.X.Scale/2) and
			object.Position.Y.Scale < PlayerHitbox.Position.Y.Scale + PlayerHitbox.Size.Y.Scale and
			object.Position.Y.Scale + object.Size.Y.Scale > PlayerHitbox.Position.Y.Scale
		then
			collision = true
			end
	end

			if not collision then
			PlayerHitbox.Position = PlayerHitbox.Position - UDim2.new(.001*runspeed,0,0,0)
			inboundary = false
			end
	PlayerHitbox.Sprite.ImageRectOffset = Vector2.new(120,25)
	PlayerHitbox.Sprite.ImageRectSize = Vector2.new(-80,80)
end

function GoRight()
	local collision = false
	local count = 0
	local Platform = GameFrames:GetChildren()
	for index,object in pairs(Platform) do
		if
			object.Position.X.Scale < PlayerHitbox.Position.X.Scale + PlayerHitbox.Size.X.Scale and
			object.Position.X.Scale > PlayerHitbox.Position.X.Scale + (PlayerHitbox.Size.X.Scale/2) and
			object.Position.Y.Scale < PlayerHitbox.Position.Y.Scale + PlayerHitbox.Size.Y.Scale and
			object.Position.Y.Scale + object.Size.Y.Scale > PlayerHitbox.Position.Y.Scale and object.Name ~= "Semi-Solid"
			
		then
			collision = true
				
			end
	end
			if PlayerHitbox.Position.X.Scale <= .4 then
					if not collision then
			PlayerHitbox.Position = PlayerHitbox.Position + UDim2.new(.001*runspeed,0,0,0)
			inboundary = false
			end
	
		else
			if not collision then
				PlayerHitbox.Position = UDim2.new(.4,0,PlayerHitbox.Position.Y.Scale,0)
			
				end
			inboundary = true
		
		end
	
	PlayerHitbox.Sprite.ImageRectOffset = Vector2.new(35,25)
	PlayerHitbox.Sprite.ImageRectSize = Vector2.new(80,80)
	
end


function CheckGround()
	local collision = false
	local Y = 0
	local Platform = GameFrames:GetChildren()
	for index,object in pairs(Platform) do
		if
			object.Position.X.Scale < PlayerHitbox.Position.X.Scale + PlayerHitbox.Size.X.Scale and
			object.Position.X.Scale + object.Size.X.Scale > PlayerHitbox.Position.X.Scale and
			object.Position.Y.Scale < PlayerHitbox.Position.Y.Scale + PlayerHitbox.Size.Y.Scale and
			object.Position.Y.Scale > PlayerHitbox.Position.Y.Scale + (PlayerHitbox.Size.Y.Scale/2)  and object.Name ~= "Semi-Solid"
		then
			return {true,object.Position.Y.Scale}
			end
			
	end
	return {false,0}
end
function Bump()
	local collision = false
	local Y = 0
	local Platform = GameFrames:GetChildren()
	for index,object in pairs(Platform) do
		if
			object.Position.X.Scale < PlayerHitbox.Position.X.Scale + PlayerHitbox.Size.X.Scale and
			object.Position.X.Scale + object.Size.X.Scale > PlayerHitbox.Position.X.Scale and
			object.Position.Y.Scale < PlayerHitbox.Position.Y.Scale + PlayerHitbox.Size.Y.Scale and
			object.Position.Y.Scale > PlayerHitbox.Position.Y.Scale - (PlayerHitbox.Size.Y.Scale/2)  and object.Name ~= "Semi-Solid"
		then
			return {collision,object.Position.Y.Scale}
			end
			
	end
	return {false,0}
end
function Jump(S,Bind,K)
	if Bind == Enum.UserInputState.Begin then
		local Function = CheckGround()
	local IsOnGround = Function[1]
	local FloorYPos = Function[2]
		if IsOnGround and not IsJumping then
	IsJumping = true
			
	script.Parent.Jump:Play()
	
				YBasedVelocity = .03
		
			end
		end
end




function Render(NextRender)
	local Function = CheckGround()
	local IsOnGround = Function[1]
	local FloorYPos = Function[2]
	if left then
		GoLeft()
	elseif right then
		GoRight()
	end
	
	if IsJumping then
		YBasedVelocity = YBasedVelocity - .001
		IsFalling = true
		if YBasedVelocity <= -0.01 then
			YBasedVelocity = 0
			IsJumping = false
			IsFalling = false
		end
	end
	if not IsJumping then
		if IsOnGround then
			YBasedVelocity = 0
			PlayerHitbox.Position = UDim2.new(PlayerHitbox.Position.X.Scale,0,FloorYPos-PlayerHitbox.Size.Y.Scale,0)
			
		elseif YBasedVelocity > -0.01 then
			YBasedVelocity = YBasedVelocity -.001
			IsFalling = true
		end
	end
	if inboundary then
					GameFrames.Position = GameFrames.Position - UDim2.new(.002,0,0,0)
	end
	PlayerHitbox.Position = PlayerHitbox.Position - UDim2.new(0,0,YBasedVelocity,0)
end



GameRender:BindToRenderStep("GameRender",Enum.RenderPriority.Input.Value, Render)

CAS:BindAction("Left",CheckLeft,true,Enum.KeyCode.Left)
CAS:BindAction("Right",CheckRight,true,Enum.KeyCode.Right)
CAS:BindAction("Jump",Jump,true,Enum.KeyCode.Z)
CAS:BindAction("Run",Run,true,Enum.KeyCode.X)
for timer = 30,0,-1 do
	if timer == 99 then
		print("Hurrry up!")
		script.Parent.TimerCount.Text = string.format('%i%.2i', timer/100, timer%100)
		else
		script.Parent.TimerCount.Text = string.format('%i%.2i', timer/100, timer%100)
		wait(1)
		end
		end
script.Parent.Death:Play()
script.Parent.BGMusic:Stop()

Here’s the video:

2 Likes

Rather than checking collision against the ‘Position’ of objects, try the AbsolutePosition (and size).

3 Likes

Okay, I’ll try. :slight_smile:

1 Like

I Tried to, but it won’t work… :frowning:

1 Like

Sorry I don’t have much time to look at the code right now but I believe that in all instances, this can help:

3 Likes

Do you know how do i achieve slopes? (I REALLY SUCK AT MATH :sweat_smile: :sweat_smile:)

1 Like

I don’t want to use absolutepos.

1 Like