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

Need help, projectile script falls ontop of me not sure why?

Asked by 3 years ago

My projectile script shoots a shadow ball thingy to the mouse, the mousepos is fired over from a localscript. It works well but sometimes it just falls on your head? help appreciated.

https://gyazo.com/90441ec262916cbbd19e76cc27157d42

local shadow = game.ServerStorage.MAGICKS:WaitForChild("Shadow")
local shadowDMG = 60

game.ReplicatedStorage.shadowService.OnServerEvent:Connect(function(player, mouse, origin)
    local character = player.Character
    local newShadow = shadow:Clone()
    newShadow.CFrame = character.HumanoidRootPart.CFrame

    local shadowVelocity = Instance.new("BodyForce")
    shadowVelocity.Force = (mouse.Position)
    shadowVelocity.Parent = newShadow



    newShadow.Parent = workspace

    local touchCon

    touchCon = newShadow.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name ~= player.Name then
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - shadowDMG
                if touchCon ~= nil then touchCon:Disconnect() end
                newShadow:Destroy()
            end
        end 
    end)

    wait(4)
    if touchCon ~= nil then touchCon:Disconnect() end
    newShadow:Destroy()
end)


1 answer

Log in to vote
0
Answered by 3 years ago

The force of your shadowVelocity should be the direction from either the character to the mouse position or the camera to the mouse position (your choice). This would be done like so...

local POWER = 10
local character = LocalPlayer.Character

local force = (mouse.Hit.Position - character.PrimaryPart.Position).Unit * POWER

or

local POWER = 10
local camera = workspace.CurrentCamera

local force = (mouse.Hit.Position - camera.CFrame.Position).Unit * POWER

The (pos1 - pos2).Unit gets a unit vector that points in the direction of pos2 to pos1. This vector is very small, so to make it a usable force you would want to add a scalar (power) to it.

0
So instead of starting the shadow from the humaniod root part cframe, I started it from the character primary part position. I tried using the subtraction thingy with the force but it made it so it always fell of your head i tried boosting the unit power up but still to no avail tjp8765 0 — 3y
Ad

Answer this question