Right now I’m trying to make a tweened part that always spawns on the floor below the player no matter how high they are, so I’ve attempted to use raycasts to find the floor’s position, which works.
However, after applying the position into CFrame, I try making the next CFrame influenced by the humanoidroot’s lookVector but it continues in only a single direction. Is this a latency issue or can this be fixed??
Here’s the unintended direction:
Here’s what I want:
Here is the code:
local GravityRoot = makeFakeRoot("GravityRoot")
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
--local startPos = hrp.Position
--local direction = hrp.lookVector
local magnitude = 800
local ignoreFolder = workspace.Ignore
local hitfloor, posfloor = nil
repeat
hitfloor, posfloor = clientWorkerModule.rayCastWithIgnoreList(hrp.Position, (CFrame.new(hrp.Position, hrp.Position - Vector3.new(0, 1, 0))).lookVector, magnitude, {char, ignoreFolder})
if hitfloor and hitfloor.CanCollide == false then hitfloor = nil end
task.wait()
until hitfloor or hum.FloorMaterial ~= Enum.Material.Air or charStats.StopAnimations.Value or hum.Health <= 0
if hitfloor == nil then
GravityRoot.CFrame = sentHrpCf * cf(0,23,0)
else
print(posfloor)
GravityRoot.CFrame = CFrame.new(posfloor) * cf(0,26,0)
end
local rootCF = GravityRoot.CFrame
local tweenPos = cf(hrp.CFrame.lookVector) * cf(0,0,-75)
task.delay(.75,function()
local CFpush = rootCF * tweenPos
local PushTween = tweenService:Create(GravityRoot, TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0), {CFrame = CFpush})
PushTween:Play()
game.Debris:AddItem(GravityRoot,4)
end)
For reference; clientWorkerModule.rayCastWithIgnoreList is just workspace:FindPartOnRayWithIgnoreList(Ray.new(pos, dir.unit * (max or 999.999)), ignoreList)
