Big brain maths question that sadly IDK!

local cframe = workspace.Misc.Start

local function upd(cframe)
	local A = cframe.Position

	local _,position,norm = workspace:FindPartOnRay(Ray.new(A,cframe.LookVector*500),workspace.Misc)

	local B = position
	local _,C = workspace:FindPartOnRay(Ray.new(A,Vector3.new(0,0,-500)),workspace.Misc)


	local AB = math.abs((A-B).Magnitude)
	local AC = math.abs((A-C).Magnitude)
	local BC = math.abs((C-B).Magnitude)

	local a = math.deg(math.acos(BC / AB))
	local anglecf = CFrame.Angles(0,math.rad(a-270),0)
	return anglecf
end

also here is my final script

nvm it was temporary happiness it worked only for parts not cameras

okay so that worked… wow

The math.abs is kinda pointless because .Magnitude never returns negativ values.
And changing your angle unit from radiants to degree to radiants is also unnessecary expensiv.
try instead without changing it to degree and just substract 1.5*math.pi from a.

1 Like

ok now for somereason it is also adding the players head movement and making it looks really wonky
(sorry for 2 fps gameplay)

1 Like

can i see ur code? If u get the head position from Character.Head.Position the animation movement of the head will influenze the position. Try instead Camera.CFrame.Position

oh sorry forgot to give that haha :sweat_smile:

local Frame = script.Parent
local CWorkspace = Frame.Workspace
local Camera = Instance.new("Camera")
Camera.Parent = Frame
Frame.CurrentCamera = Camera
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")

local function UpdateWorkspace()
	CWorkspace:ClearAllChildren()
	for _,Inst in pairs(workspace:GetChildren()) do
		if Inst.Name ~= "Camera" and Inst.Name ~= "Terrain" then
			if Inst.Archivable then
				local Clone = Inst:Clone()
				Clone.Parent = CWorkspace
			end
		end
	end
	for _,plr in pairs(game.Players:GetPlayers()) do
		local char = plr.Character or plr.CharacterAdded:Wait()
		local model = Instance.new("Model",CWorkspace)
		model.Name = plr.Name
		for _,part in pairs(char:GetChildren()) do
			local c = part:Clone()
			c.Parent = model
		end
	end
end

repeat
	wait()
until game:IsLoaded()

local function upd(startCFrame)
	local Direction = startCFrame.lookVector
	local position = startCFrame.p
	local ray = Ray.new(position, Direction * 500)
	local hit, position, surfaceNormal = game.Workspace:FindPartOnRay(ray)
	local reflectedNormal = (Direction - (2 * Direction:Dot(surfaceNormal) * surfaceNormal))
	return CFrame.lookAt(Vector3.zero, reflectedNormal) + position + reflectedNormal * 10
end

game:GetService("RunService").RenderStepped:Connect(function()
	UpdateWorkspace()
	CWorkspace.PrimaryPart = CWorkspace:FindFirstChild("Mirror",true)
	CWorkspace:FindFirstChild("MFrame",true).Transparency = 1
	CWorkspace.PrimaryPart.Transparency = 1
	local primpartpos = CWorkspace.PrimaryPart.Position
	local x,y,z = upd(workspace.CurrentCamera.CFrame):ToOrientation()
	Camera.CFrame = CFrame.new(primpartpos)*CFrame.Angles(x,y,z)
end)
1 Like

I made once with this reflection formula a little render engine inside roblox which gives pretty cool images
grafik

You’re welcome, glad to see this problem come to an end! Good luck with the rest of your project.

edit: nvm looks like it didn’t end.

1 Like

nice but uhh how did u do it? with the cam?

wdym? do ya mean the image i posted made by my render engine?

yea how u made that reflection and can you fix my code to make itlike that? I am not good with maths. the problem is IDK WHY it offsets the player characters cframe!

That would work. What i made is a COMPLET render engine inside roblox visualized with ui frames.
basicly what i am doing is tracing a ray for each pixel and then do some light/shader calculations.
a image with a size of 400 by 300 pixel takes around 30 sec. to render that means u would have 0.0333 FPS

hmmm well NOT GONNA DO THAT NOW LOL well then just help me with a way to fix the code with the players head offset cf even when I am not adding any!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.