Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My dashing script is not working even after i tried raycasting, what do i do now?

Asked by 1 year ago

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

01local UIS = game:GetService("UserInputService")
02local player = game.Players.LocalPlayer
03 
04local deb = false
05 
06player.CharacterAdded:Connect(function(char)
07 
08    local char = player.Character
09    local Hum = char:WaitForChild("Humanoid")
10    local HRP = char:WaitForChild("HumanoidRootPart")
11 
12    UIS.InputBegan:Connect(function(input, gpe)
13 
14        if gpe then return end
15 
View all 76 lines...

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.

1 answer

Log in to vote
0
Answered by 1 year ago

You're not checking collision at all, you're just checking if ray.Position exists, which it does. To check if the intersection has collision, you get the part the ray intersected at and check its collision by checking if the CanCollide property is true or false.

To avoid HumanoidRootPart leaving the rest of the limbs, use PivotTo().

01local UIS = game:GetService("UserInputService")
02local player = game.Players.LocalPlayer
03 
04local deb = false
05 
06UIS.InputBegan:Connect(function(input, gpe)
07    if gpe then return end
08 
09        if input.KeyCode == Enum.KeyCode.E and deb == false then
10        local char = player.Character
11        if not char or not char.Parent then
12            char = player.CharacterAdded:Wait()
13        end
14 
15        local Hum = char:WaitForChild("Humanoid")
View all 70 lines...
0
Thank you, it worked. Man i feel like an idiot now, but either way, this was really helpful. I appreciate it lolmarios2647 46 — 1y
Ad

Answer this question