I’m trying to make my viewmodel push back whenever it gets close to a wall, depending on how close it is.
But it’s inverted, basically.
Not close, code is acting as if I was at the closest point, in reality I’m at the farthest point
Very close, code is acting as if I was at the farthest point, in reality I’m at the closest point
Code:
local Origin = Camera.CFrame.Position
-- fp2c is the distance from the muzzle to the camera, used for raycasting
local Direction = Camera.CFrame.LookVector*(Tool.FP2C.Value)
local Cast = game.Workspace:Raycast(Origin, Direction, Params)
if Cast then
local Distance = Cast.Distance
print(Distance)
script.Offset0.Value = CFrame.new(0, 0, Distance) -- t
else
script.Offset0.Value = CFrame.new(0, 0, 0)
end




