Hello. I have this code:
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
local Bullet = Instance.new("Part")
Bullet.Parent = game.Workspace
Bullet.CanCollide = false
Bullet.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(90),0)
local Direction = (mouse.Hit.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Unit
Bullet.AssemblyLinearVelocity = Direction*100
end)
The line I am intersted in is:
local Direction = (mouse.Hit.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Unit
That line and this give the same result:
local Direction = (mouse.Hit.Position).Unit
I don't understand why we need to use the first one? Can anyone explain the math?

1 comment
Math isnt my strongest side so excuse me if i get something wrong here. Basically the first line is creating a unit vector from the Mouse position to the RootPart position. So basically you have a line from the mouse position to the rootpart.