How to impulse the character to a part

Hi, I am making an impulse system for the player when he clicks on a part of the screen. What I want to know is how to make that boost from the character to the part. Every time the player clicks, a part is created, and the character would have to be boosted to that part, but I have no idea how to make that boost.

This is the code (Server):

local function createPart(origin, direction)
    local midpoint = origin + direction/2

    local p = Instance.new("Part",workspace.Cordroptero)
    p.Anchored = true
    p.CanCollide = false
    p.CFrame = CFrame.new(midpoint, origin)
    debris:AddItem(p, 1)
end

mouseHitEvent.OnServerEvent:Connect(function(plr, mouse, camera, rp)
    local char = plr.Character
    local hum = char:WaitForChild("Humanoid")

    local params = RaycastParams.new()
    params.FilterDescendantsInstances = {char}
    params.FilterType = Enum.RaycastFilterType.Blacklist

    local range = 40
    local origin = rp.Position
    local direction = (mouse - origin).Unit * range
    local result = workspace:Raycast(origin, direction, params)
    createPart(origin,direction)
end)

1 Like

You can use :ApplyImpulse() but keep in mind that the client owns the character (and its assembly, so any parts welding to the character!), so you need to apply it from a script running on the client: Quickly Launch the player upwards when touching a part - #4 by azqjanna

3 Likes

It makes sense, but how could I apply that impulse to the part? Like using the CFrame or something?

1 Like

I found a solution, My solution was to create an AlingPosition on the player to drive towards the part. I will polish this more to make it look better.

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