Ad
Log in to vote
0

Problem with custom character movement with raycast normal?

Asked by
Dexiber 272 Moderation Voter
9 days ago

So basically, I'm trying to make a smooth slope moving system like Speed Run 4: https://web.roblox.com/games/183364845/Speed-Run-4

I tried it myself, but there's an issue.

The Code:

wait()

local plr = game.Players.LocalPlayer
local char = plr.Character
local human = char.Humanoid
local root = char.HumanoidRootPart

local bv = Instance.new("BodyVelocity",root)

local speed = 100

while wait() do
    local moveDir = human.MoveDirection

    if moveDir.Magnitude > 0 then
        local mass = 0

        for i,v in pairs(char:GetDescendants()) do
            if v:IsA("BasePart") then
                mass += v:GetMass()
            end
        end

        local rayParams = RaycastParams.new()

        rayParams.FilterDescendantsInstances = {char}
        rayParams.FilterType = Enum.RaycastFilterType.Blacklist

        local ray = workspace:Raycast(root.Position,Vector3.new(0,-4,0),rayParams)

        if ray then
            print("a")

            bv.Velocity = (moveDir * speed) * ray.Normal
        else
            bv.Velocity = moveDir * speed
        end

        bv.MaxForce = Vector3.new(100000,0,100000)
    else
        bv.Velocity = Vector3.new(0,0,0)
        bv.MaxForce = Vector3.new(0,0,0)
    end
end

What happens: https://gyazo.com/ad078f271d2407b4909cc9264809fd69

The problem: I'm not experienced with raycast normals and other things like cross and dot. What's happening is when I try to move, I just seem to be going downward when on the ground.

Be free to ask for more information, I really need help with this and I'd be very happy to get an answer. Thank you!

Answer this question