How do I make a projectile shoot in the direction of the mouse?

Right now the part shoots out but it doesn’t follow the mouse

Use UIS and mouse.Hit.p to get the mouse’s position in 3D space.

So basically lets break this down into mini problems that are easier to understand.

Alright so you want a projectile to shoot from the direction of the mouse, first things first, most likely you want other players to see said “projectile” so were going to need a remoteEvent for that!

1st Part
Create a new remoteEvent in ReplicatedStorage and call it “Test”!

2nd Part
Create a new local script in either StarterCharacterScripts or StarterPack!

3rd Part
Inside of that local script define the path to the remoteEvent you made for the 1st Part

-- LOCAL SCRIPT
local remote = game.ReplicatedStorage.Test

4th Part
Inside of that local script your doing to need some input so the script can detect which key or mousebutton is being pressed, so lets UserInputService for that

-- LOCAL SCRIPT
local remote = game.ReplicatedStorage.Test
local UserInputService = game:GetService("UserInputService")

5th Part
Define the player’s mouse because we’ll be using that later!

-- LOCAL SCRIPT
local plr = game.Players.LocalPlayer
local remote = game.ReplicatedStorage.Test
local UserInputService = game:GetService("UserInputService")
local Mouse = plr:GetMouse()

6th Part
Use the InputBegan event with the UserInputService Variable you created!

UserInputService.InputBegan:Connect(function(input,typing)
      if input.UserInputType == Enum.UserInputType.MouseButton1 then
         remote:FireServer(Mouse.Hit.p)
     end
end

This should get you started on it fairly well!

5 Likes

hey im using this right now but how can i make something face the direction of the mouse not spawn on the mouses position