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.
✓ ANSWER ACCEPTED
How Would I go About Shooting a Projectile in The Direction of a Mouseclick?
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
