Provide an overview of:
- What does the code do and what are you not satisfied with?
The code fires a ray from the players humanoidrootpart to the players lookvector and if it hits something then it will update players HRP cframe to that result position else if it doesn’t hit anything then it will update HRP cframe to the full length
module.Blink = function(player)
local HRP = player.Character:FindFirstChild("HumanoidRootPart")
local BlinkDebounce = player:FindFirstChild("Debounce")
local AbilityCD = 5
local BlinkDistance = 25
if not BlinkDebounce then
local Charges = Instance.new("BoolValue")
Charges.Name = "Debounce"
Charges.Parent = player
local Rayorigin = HRP.Position
local Raydirection = HRP.CFrame.LookVector * BlinkDistance
local Raycastparams = RaycastParams.new()
Raycastparams.FilterDescendantsInstances = {player.Character}
Raycastparams.FilterType = Enum.RaycastFilterType.Exclude
local Raycastresult = workspace:Raycast(Rayorigin, Raydirection, Raycastparams)
if not Raycastresult then
HRP.CFrame = HRP.CFrame + HRP.CFrame.LookVector * 25
else
local raycasthitposition = Raycastresult.Position
HRP.CFrame = CFrame.new(raycasthitposition - HRP.CFrame.LookVector * 2)
end
else
task.delay(AbilityCD, function()
BlinkDebounce:Destroy()
end)
end
end
- How (specifically) do you want to improve the code?
Currently the way it updates players cframe causes some issues with what direction the player is facing. I would have time when it turns the player 180* if the ray hits a wall or the player turning sideways without me moving the camera at all.