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
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.
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
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)
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