My dashing script is not working even after i tried raycasting, what do i do now?
So, i recently started making the combat system for my game. First thing i made was the "dashing system" (not really dashing, but the idea behind it is that every time the player presses E, they teleport a few studs forward with any NPCs that are infront of them before the teleport get knocked up and stunned)
Well, first problem i ran into was that the player can teleport not only through walls, but if they are too chonky, they can teleport inside them.
Someone recommended that i use raycasting, which i learned and used in the script below, which of course, still has problems
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local player = game.Players.LocalPlayer |
06 | player.CharacterAdded:Connect( function (char) |
08 | local char = player.Character |
09 | local Hum = char:WaitForChild( "Humanoid" ) |
10 | local HRP = char:WaitForChild( "HumanoidRootPart" ) |
12 | UIS.InputBegan:Connect( function (input, gpe) |
14 | if gpe then return end |
16 | local RayPos = HRP.Position |
17 | local RayDirection = HRP.CFrame.LookVector * 50 |
18 | local RayParams = RaycastParams.new() |
19 | RayParams.FilterDescendantsInstances = { |
21 | game.Workspace [ "Drooling Zombie" ] , |
22 | game.Workspace.Baseplate |
26 | RayParams.FilterType = Enum.RaycastFilterType.Blacklist |
27 | RayParams.IgnoreWater = true |
29 | if input.KeyCode = = Enum.KeyCode.E and deb = = false then |
31 | local ray = workspace:Raycast(RayPos, RayDirection, RayParams) |
34 | local collision = ray.Position |
45 | HRP.Position = collision |
54 | elseif not collision then |
63 | HRP.CFrame = HRP.CFrame + (HRP.CFrame.LookVector * 50 ) |
Well, the problem with it is that there are no errors, but, when the ray has collision the HumanoidRootPart gets teleported and it makes the camera all janky because it leaves the rest of the player behind.
Also, even if there are no errors, if the ray has no collision, then the script flat out does not run, at all, even if i have an Elseif statement inside that clearly states that "if there's no collision just do this"
I really need help with this one homies. I appreciate any of it.