# What is happening here? (VectorToObjectSpace())

What is happening here?

local vector = (HRP.CFrame - HRP.CFrame.p):VectorToObjectSpace(surfaceHit)

My assumption: its taking the HRP’s CFrame, and removing the positional values.

1. So now we are left with the rotational values?
2. then it takes the offset between the HRP’s CFrame rotational values, and a Vector3? - How is that possible if Vector3’s dont have rotational values?

FULL CODE:
Code Function - Slope Tilting

``````local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local lowerTorso, HRP = char:WaitForChild("LowerTorso"), char:WaitForChild("HumanoidRootPart")

game:GetService("RunService").RenderStepped:Connect(function()
local ray = Ray.new(HRP.Position, Vector3.new(0, -(char.Humanoid.HipHeight + 2), 0))
local _, _, surfaceHit = workspace:FindPartOnRayWithIgnoreList(ray, {char})
local vector = (HRP.CFrame - HRP.CFrame.p):VectorToObjectSpace(surfaceHit) -- The code being mentioned
print(surfaceHit.CFrame)
print(vector)
lowerTorso.Root.C0 = CFrame.new(0,-0,0,1,0,0,0,1,0,0,0,1) * CFrame.Angles(vector.z, 0, -vector.x)

end)

``````

1 is correct.
For 2 though, what it’s doing is converting surfaceHit into the rotational space we are left with.
So when it reads VectorToObjectSpace, the Vector bit is actually the Vector3 inside of the parentheses.

1 Like

Is it returning an offset of some sort? like “:ToObjectSpace”, and does it consider the object as the origin like “:ToObjectSpace”?

The reason im asking this is because the only difference I see between it and “:ToObjectSpace” is that it has “vector” in its name, or is the name deceiving and functions totally different?

Yeah it’s the same thing but it takes a vector instead of a CFrame

1 Like