#Subway surf movement system

22 messages · Page 1 of 1 (latest)

stone loom
#

Here is the code :
local UIS = game:GetService("UserInputService")

local camerapart = game.Workspace:WaitForChild("CameraPart")
local speed = -5

local laneWidth = 8
local currentLane = 2

UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.A then
-- Move left
currentLane = math.max(currentLane - 1, 1)
elseif input.KeyCode == Enum.KeyCode.D then
-- Move right
currentLane = math.min(currentLane + 1, 3)
end
end
end)

game:GetService("RunService").Heartbeat:Connect(function()
local targetPosition = (currentLane - 2) * laneWidth
local currentPosition = camerapart.Position.X
local netvalue = targetPosition - currentPosition
local movement = math.clamp(netvalue, -0.9, 0.9)

camerapart.Position = camerapart.Position + Vector3.new(movement, 0, speed)

end)

the code works fine, but after a certain distance the camera part goes back to its original position for some reason and starts to move again.
The video i provied shows the issue

#

there was no cut in the video. the part literally went back to its original position

crystal lark
stone loom
#

what

sour lotus
# stone loom what

iirc, subway surf doesn't move the player, it moves the map to the player, which is alot more simple to script imo

stone loom
#

ok, but i am trying to move the part(not the player). the part is controlled by the player

sour lotus
#

It seems to move fine

stone loom
#

in the video u can see it works, but after some distance, the camerapart seems to tp back to starting position

#

and then moves again

sour lotus
#

Try to remove the math.clamp line

stone loom
#

but that is needed to move the cube or needed to change lanes

sour lotus
#

Ohh

stone loom
#

if the value is +ve, it would clamp to 0.9, so the speed of the cube will go diagonally

sour lotus
#

Does it constantly go back when it reaches that point?

#

Hmm interesting

stone loom
#

yes

#

like it goes on a loop. lets say , for example the cube starts at 0,0,0 and moves along -z axis at the speed of -1. so after it reaches to a point (say 0,0,1000), the cube goes back to original position)ie 0,0,0)

stone loom
left shadowBOT
#

studio** You are now Level 3! **studio

stone loom
#

nvm it is much harder compared to what i am trying to achieve

stoic moth
#

What you're trying to achieve will eventually cause the game to lose performance

#

Roblox's physics and rendering engine won't be able to handle the larger positions as the player gains ever-increasing distance away from the world origin