Hi, so i made this new ability for my game which essentially allows the player to teleport forwards instantly. It works by Raycasting 100 studs in front of the player, if there’s no part hit, then just teleport to the end of the raycast like normal, however, if there is, then just teleport the player to the location of the raycast hit.
It works just fine, however, one problem is that the character faces the direction the raycast hit part is facing when teleported. This isn’t what i want, i want the character to keep his original rotation. I don’t wanna use MoveTo()
because it’ll teleport the player to the very top of the raycast hit part, which isn’t what i want either. It seems to work when shiftlock is on, but not when it isn’t.
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
--------------------------------------
local Raycast = workspace:Raycast(Root.Position, Root.CFrame.LookVector.Unit * 100, Params)
if Raycast and Raycast.Instance then
if Humanoid.FloorMaterial ~= Enum.Material.Air then
Character:PivotTo(CFrame.new(Root.Position + Root.CFrame.LookVector.Unit * Raycast.Distance))
else
Root:ApplyImpulse(Vector3.new(0, 1000, 0))
--------------------------------------
Character:PivotTo(CFrame.new(Root.Position + Root.CFrame.LookVector.Unit * Raycast.Distance))
end
else
if Humanoid.FloorMaterial ~= Enum.Material.Air then
Character:MoveTo(Root.Position + Root.CFrame.LookVector.Unit * 100)
else
Root:ApplyImpulse(Vector3.new(0, 1000, 0))
--------------------------------------
Character:MoveTo(Root.Position + Root.CFrame.LookVector.Unit * 100)
end
end