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

Bullet / Gun help with the math?

Asked by 2 years ago

Hello! I have this piece of 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 interested in is this:

local Direction = (mouse.Hit.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Unit

What is the difference between that and this?:

local Direction = (mouse.Hit.Position).Unit

They give the same results, but everywhere I go the first one is the one being used. Any idea why?

Answer this question