Hello, I am currently trying to make a Paper.io game in roblox. I have two problems:
First of all, as you can see in the picture sometimes when the block curves, the beams are not perfectly lined up. How would I fix this?
Here is the script for the creation of the beams:
local Players = game:GetService("Players")
local Runservice = game:GetService("RunService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Player.CharacterAdded:Connect(function(C)
Character = C
end)
local REFRESH_RATE = 0 -- how often does it check the character's position
local RESOLUTION_DISTANCE = 1 -- how far does the character need to be from its last position to make a new point
local Markers = {}
local LastAngle = 0
function DegreeBetweenVectors(a, b)
return math.deg(math.acos(math.clamp(a.Unit:Dot(b.Unit),-1,1)))
end
local function MakeMarker(Position)
local Marker = Instance.new("Part")
Marker.CanCollide = false
Marker.CanQuery = false
Marker.CanTouch = false
Marker.Size = Vector3.new(0.1,0.1,0.1)
Marker.Color = Color3.fromRGB(255, 0, 0)
--Marker.Transparency = 1
Marker.Anchored = true
Marker.Position = Position
Marker.Parent = workspace
local Attachment = Instance.new("Attachment")
Attachment.Parent = Marker
LastAngle = 0
if #Markers ~= 0 then
local Beam = Instance.new("Beam")
Beam.Attachment0 = Attachment
Beam.Attachment1 = Markers[#Markers]:FindFirstChildOfClass("Attachment")
Beam.Parent = Marker
Beam.FaceCamera = true
end
table.insert(Markers,Marker)
end
local PreviousTime = os.time()
Runservice.Heartbeat:Connect(function()
if PreviousTime + REFRESH_RATE < os.time() then
if Character then
local ConsideredPosition = Character:GetPivot().Position
if #Markers == 0 or (ConsideredPosition - Markers[#Markers].Position).Magnitude >= RESOLUTION_DISTANCE then
local PreviousMarker = Markers[#Markers]
if #Markers >= 2 then
local DegreesBetween = DegreeBetweenVectors(ConsideredPosition - PreviousMarker.Position,PreviousMarker.Position-Markers[#Markers-1].Position)
local Marker = Markers[#Markers]
print(LastAngle)
if DegreesBetween < 3 and LastAngle < 3 then
LastAngle += DegreesBetween
Marker.Position = ConsideredPosition
return
end
end
MakeMarker(ConsideredPosition)
end
end
end
end)
Also, another problem is that for some reason the creation of the beams are desynced with the server
as you can see here, it looks fine
However on the server, the beams and the block are desynced. Why is this?
I am using :MoveTo() to move the block
Thanks in advance for any help