I am trying to make a script to avoid the floating point precision, i am making a really large game, so it’s really important. It will be a singleplayer game and the script runs in the server, to make life easier.
-
This script works by making the player always close to the origin, teleporting the player back to 0, 0, 0 when too far (In the script it is 10 studs, just for testing) and moving the world to the opposite direction of the player, wich should create a smooth ilusion of the player moving, when in reality the player is stuck inside a box and it is the world that moves.
-
It kinda works, the player and the world are able to move, but the world doesn’t move properly, it is kinda stuttery.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local world = workspace.World --A model that contains every part
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
print("Character loaded")
RunService.Stepped:Connect(function()
local oldCFrame = character.HumanoidRootPart.CFrame --Set player CFrame to a var
if math.abs(oldCFrame.Position.X) >= 10 or math.abs(oldCFrame.Position.Y) >= 10 or math.abs(oldCFrame.Position.Z) >= 10 then
character:PivotTo(CFrame.new(0, 0, 0) * oldCFrame.Rotation)
local pivot = world:GetPivot()
world:PivotTo(pivot - oldCFrame.Position) --Changes model pos to match player pos
end
end)
end)
end)