Player dashing gets flung when tool is not equipped

So I’m trying to make a dash mechanic in the game, but when I dash into a wall what happens differs based on whether the tool is equipped or not. When the tool is equipped, it doesn’t fling but when the tool isn’t equipped, the player gets flung.

Here’s a video of the problem:

I don’t know what could be making the player go all over the place when they don’t equip the tool. btw the dash uses the same animation for both equipped and not equipped.

Here’s the code to make the velocity for the dash:

local boost:LinearVelocity = script.Boost:Clone() -- linear velocity object
boost.Parent = character.PrimaryPart
boost.Attachment0 = character.PrimaryPart.RootAttachment

local directionunit = character.PrimaryPart.CFrame.LookVector

boost.VectorVelocity = directionUnit * DodgeConfiguration.Distance.Value/DodgeConfiguration.Time.Value

local t = TweenService:Create(
	boost,
	TweenInfo.new(DodgeConfiguration.Time.Value, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
		{VectorVelocity = Vector3.new()}
	)

t:Play()
	

Does anyone know the issue? Any help would be very appreciated.

Update: any tool instance, even an empty tool instance would prevent the dash from flinging the player.

2 Likes

Why not just not allow the player to be able to dash in the first place if they are too close to in front of a wall?

Also if you could hand over the texture id of those floors and walls that would be much appreciated

3 Likes

The problem with that is the player can’t dash up slopes because the raycast thinks the slope is a wall.

btw here’s the texture id: rbxassetid://17665514726

2 Likes

thanks!

then just put slopes on an ignore list or if that doesnt work check the normal of where it hit then get the cross product of the normal and the world upvector and then get the angle and then if the angle is more then some arbituary value then do something

1 Like

Here is a refined version of your script with some additional checks to ensure the dashing mechanic works smoothly:

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local rootAttachment = humanoidRootPart:FindFirstChild("RootAttachment")

local DodgeConfiguration = {
    Distance = Instance.new("NumberValue"),
    Time = Instance.new("NumberValue")
}
DodgeConfiguration.Distance.Value = 50
DodgeConfiguration.Time.Value = 0.5

local function dash()
    if not rootAttachment then return end

    local boost = Instance.new("LinearVelocity")
    boost.Parent = humanoidRootPart
    boost.Attachment0 = rootAttachment

    local directionUnit = humanoidRootPart.CFrame.LookVector
    boost.VectorVelocity = directionUnit * (DodgeConfiguration.Distance.Value / DodgeConfiguration.Time.Value)

    local tweenInfo = TweenInfo.new(DodgeConfiguration.Time.Value, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
    local tween = TweenService:Create(boost, tweenInfo, {VectorVelocity = Vector3.new()})
    
    tween:Play()
    tween.Completed:Connect(function()
        boost:Destroy()
    end)
end

-- Call the dash function
dash()

Explanation

  1. Ensure TweenService and Players Services: Make sure you’re getting these services correctly.
  2. Retrieve Character and HumanoidRootPart: Wait for the player’s character and HumanoidRootPart to be available.
  3. Check for RootAttachment: Ensure that the RootAttachment is present before applying LinearVelocity.
  4. Create and Configure LinearVelocity: Clone or create a new LinearVelocity object and set its properties.
  5. Use Tween: Create a tween to smoothly transition VectorVelocity to Vector3.new(), ensuring the boost is removed after the tween completes.

Additional things

  • Tool Equipped Check: If you need to ensure this only happens when a tool is equipped, you can add a check to see if the player has a specific tool equipped.
  • Physics Settings: Adjust the physics properties of the player’s character, if necessary, to prevent unintended flinging.

This script should provide a smoother dashing experience and prevent the player from being flung unexpectedly. If you still encounter issues, you might need to adjust the physics properties or investigate other potential interactions in your game.

1 Like

okay thank you all for providing suggestions but I solved the problem. It turns out the player’s rotation speed went crazy high when they hit the wall when dashing. I don’t know why, but this flung the player when they hit a wall.

I have a script where if there is tool equipped then it automatically does shift lock, preventing the player from rotating unless the mouse moves. It used an AlignOrientation object which constantly set the orientation of the player to not rotate based on whatever physics happens arounds the player. I just added the AlignOrientation object to the player’s humanoid root part during the time they dash, so they won’t rotate and be flung into the void.

You can also use humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown,false) to prevent the same thing from happening.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.