Player flinging when dashing onto a collidable part

The question/problem is pretty straightforward, when the player dashes onto a collidable part it flings them:


I tried raycasting like:

local raycast = workspace:Raycast(head.Position, head.Position + Vector3.new(0,0,-2), raycastParams)

Im not entirely sure on that one but you get the point.

Thanks!!

My idea would be to raycast ahead of the player, and if there is a part in the way, only dash the distance up to that part so that the player doesn’t mash up onto it and fling.

1 Like

Yes i tried that and it didnt work.

1 Like

The direction you are putting for the raycast is not relative to the character, it will always point -2 on the Z axis. You need to point the raycast the same direction that the character is. Only way I know how to do this is CFrame:ToWorldSpace()

1 Like

Isnt it putting it relative to the player head?

1 Like

Yes the position is relative, but the direction isn’t. It’s always going to point in the same direction, but it will originate from the head.

1 Like

Isn’t that putting it relative to the world space?
In my understanding, we want it relative to the player.

Maybe you mean
CFrame:ToObjectSpace()

Nevermind.

CFrame:ToWorldSpace(Vector3) will add the Vector3 onto the CFrame in local space (factoring in rotation aswell) and return that position in world space.

1 Like

I tried

head.CFrame.LookVector * 100

And it works but its not what i expect, i tween the character -2 studs but i dont know about CFrame since you can’t use CFrames in tweening

Because i can’t just do
head.CFrame.LookVector * -2

1 Like

One problem, i cant set the world space to a position/vector3.

im kind of new to cframes so yeah. Sorry about that

1 Like

Hey!
I have been testing things out and this worked out:

local raycastResult = workspace:Raycast(HRP.Position, HRP.CFrame * HRP.CFrame.LookVector*1, raycastParams)

But another problem, it only checks one stud. So if i set it to 20 studs, it wont check the other studs (like 1-19) and only check 20, any solutions?

Edit: doing

HRP.CFrame.LookVector*500

Works but it detects too far. Is this 500 studs or is this like another thing that i have to calculate, but from my understandings its 500 studs.

Adjusting this a bit works! :smiley:

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")

print(hrp.CFrame.LookVector) --0, 0, -1

Multiplying by a scalar of 500 will increase the vector’s magnitude by a product of 500.

1 Like

LookVector will always be a unit vector, using .Unit only helps when its like velocity or something.

Edit: Oops looks like you edited your post sorry.

1 Like