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

Why is the Mouse Position always a little off in this projectile?

Asked by 3 years ago
Edited 3 years ago

Hello, I'm trying to script a fireball projectile that goes towards the mouse position, and everything works, just not as I intended it to work. For some reason the fireball doesn't go to the mouse position exactly, it is always a little off. I don't think anything other than this part of the script is necessary, but if there is anything else I could provide just tell me and I'll edit the question.

I already tried to change the line 11 and replace it for: FireballVelocity.Velocity = (Target - Fireball.Position).Unit * 50

(Target being the Mouse.hit.p ) but it didn't fix it either.

FireballInput.OnServerEvent:Connect(function(Player, Target)
    local Character = Player.Character
    local HumanoidRootPart = Character.HumanoidRootPart

    local Fireball = ServerStorage.Fireball:Clone()
    Fireball.Parent = workspace
    Fireball.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -5)

    local FireballVelocity = Instance.new("BodyVelocity", Fireball)
    FireballVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    FireballVelocity.Velocity = CFrame.new(HumanoidRootPart.Position, Target).lookVector * 50

    Debris:AddItem(Fireball, 2)
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Maybe try this.

mousehit = nil
FireballInput.OnServerEvent:Connect(function(Player, Target, Verd)
mousehit = Verd
      local Character = Player.Character
        local HumanoidRootPart = Character.HumanoidRootPart

        local Fireball = ServerStorage.Fireball:Clone()
        Fireball.Parent = workspace
        Fireball.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -5)

local FireballVelocity = Instance.new("BodyVelocity",Fireball)FireballVelocity .maxForce = Vector3.new(math.huge,math.huge,math.huge)FireballVelocity .Velocity = CFrame.new(projectileknife.Position.mousehit).lookVector*50


         Debris:AddItem(Fireball, 2)
end)
Ad

Answer this question