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

How Would I go About Shooting a Projectile in The Direction of a Mouseclick?

Asked by 5 years ago
Edited 5 years ago

I have a general understanding of most things regarding projectile motion and getting the target of a Mouseclick, but is there a way to make the projectile head towards the spot where the mouse is clicked? What about the case where Target is nil (i.e, you click the sky or something extremely far away)? Thanks so much in advance.

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago

Although the mouse's Target maybe nil sometimes, Hit won't be. We can use Hit to get a direction from the character and use that to fire something.

local plr=game.Players.LocalPlayer
local m=plr:GetMouse()

m.Button1Down:Connect(function()
    local p=Instance.new("Part")
    p.CanCollide=false
    p.CFrame=plr.Character.HumanoidRootPart.CFrame
    p.Velocity=CFrame.new(plr.Character.HumanoidRootPart.Position,m.Hit.p).lookVector*100
    p.Parent=workspace
end)
Ad

Answer this question