- I am trying to get rotational offset and position offset on my viewmodel to transition smoothly and react fast without the position bug.
Examples:
Shown at: 0:26 / 0:50
- What I currently have. In both videos listed, there’s a conflict happening between the two :Lerp()'s
--Settings/configs
local CollisionUpdate = .1
local MaxCollisionOffset = Vector3.new(0,0,-.5)
local MaxCollisionOffsetRotation = Vector3.new(0,0,-.45)
local CollisionOffset = Vector3.new(0,0,0)
local ExtraCollisionOffset = Vector3.new(0,0,0)
local function canSee(from,to,ignore)
local intIgnore = {}
for i,v in pairs(ignore) do
intIgnore[i] = v
end
local ray = Ray.new(from,to-from)
local blocked = false
local finished = false
local count = 0
repeat
count += 1
local f = workspace:FindPartOnRayWithIgnoreList(ray,intIgnore)
if f then
if f.Transparency > 0 or (f.Parent.Parent and f.Parent.Parent:FindFirstChild('Humanoid')) then
intIgnore[#intIgnore+1] = f
else
finished = true
blocked = true
end
else
finished = true
end
until finished or count > 100
local Param = RaycastParams.new()
Param.FilterType = Enum.RaycastFilterType.Exclude
Param.FilterDescendantsInstances = {intIgnore}
return workspace:Raycast(from,to-from,Param)
end
--Issue occurs in the :Lerp() areas
stepped_con = game:GetService("RunService").RenderStepped:connect(function(deltaTime)
if tool:FindFirstChild("Handle") and tool:FindFirstChild("Handle"):FindFirstChild("Main") and tool:FindFirstChild("Handle"):FindFirstChild("Main"):FindFirstChild("CollisionEnd") and tool:FindFirstChild("Handle"):FindFirstChild("Main"):FindFirstChild("GunCollisionStart") then
local Result = canSee(tool:FindFirstChild("Handle"):FindFirstChild("Main"):FindFirstChild("CollisionStart").WorldPosition, tool:FindFirstChild("Handle"):FindFirstChild("Main"):FindFirstChild("CollisionEnd").WorldPosition,{tool,character})
if Result == nil then
CollisionOffset = CollisionOffset:Lerp(Vector3.new(),CollisionUpdate)
ExtraCollisionOffset = ExtraCollisionOffset:Lerp(Vector3.new(),CollisionUpdate)
if ExtraCollisionOffset ~= Vector3.new() then
Aimoffset = Aimoffset:Lerp(aimoffset.Value,CollisionUpdate)
else
Aimoffset = Aimoffset:Lerp(aimoffset.Value,1)
end
else
CollisionOffset = CollisionOffset:Lerp(Vector3.new(CollisionOffset.X,CollisionOffset.Y,math.clamp(-Result.Distance,MaxCollisionOffset.Z,0)),CollisionUpdate)
if CollisionOffset.Z <= MaxCollisionOffsetRotation.Z then
ExtraCollisionOffset = ExtraCollisionOffset:Lerp(Vector3.new(CollisionOffset.X,CollisionOffset.Y,math.clamp(-Result.Distance,MaxCollisionOffset.Z*2,CollisionOffset.Z)),CollisionUpdate)
Aimoffset = Aimoffset:Lerp(Vector3.new(),CollisionUpdate)
end
end
end
end)