ffrostfall/ByteNet

CFrames sent from client to server have malformed orientation.

Closed this issue · 3 comments

I am sending the client printed CFrame value to the server and then printing it server side. The value on the server side does not match the one the client sent.

image

May be worth noting that this this cframe is being sent as part of a struct.

Fixed version of the cframe type (provided by Arkiuma)

local bufferWriter = require(script.Parent.Parent.process.bufferWriter)
local types = require(script.Parent.Parent.types)

local f32NoAlloc = bufferWriter.f32NoAlloc
local alloc = bufferWriter.alloc

local cframe = {
	read = function(b: buffer, cursor: number)
		local x = buffer.readf32(b, cursor)
		local y = buffer.readf32(b, cursor + 4)
		local z = buffer.readf32(b, cursor + 8)
		local rx = buffer.readf32(b, cursor + 12)
		local ry = buffer.readf32(b, cursor + 16)
		local rz = buffer.readf32(b, cursor + 20)
		
		return CFrame.new(x, y, z) * CFrame.Angles(rx, ry, rz), 24
	end,
	write = function(value: CFrame)
		local x, y, z = value.X, value.Y, value.Z
		local rx, ry, rz = value:ToEulerAnglesXYZ()
		
		-- Math done, write it now
		alloc(24)
		f32NoAlloc(x)
		f32NoAlloc(y)
		f32NoAlloc(z)
		f32NoAlloc(rx)
		f32NoAlloc(ry)
		f32NoAlloc(rz)
	end,
}

return function(): types.dataTypeInterface<CFrame>
	return cframe
end

The multiplication for the axis should happen before you collect the rx, ry, rz variables. If you swap lines 28 and 29 in cframe dataType, the CFrame works correctly.

Current:

		local axis, angle = value:ToAxisAngle()
		local rx, ry, rz = axis.X, axis.Y, axis.Z
		axis = axis * angle

Fix:

		local axis, angle = value:ToAxisAngle()
		axis = axis * angle
		local rx, ry, rz = axis.X, axis.Y, axis.Z