local a = Instance.new("Part") a .Shape = "Ball" game.Debris:AddItem(a , 5) a .Material = "Neon" a .CanCollide = true a .Size = Vector3.new(3.6,3.6,3.6) a .BrickColor = BrickColor.new("Really red") a .Transparency = 0 a .CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(mp,mp,-20) local Bd = Instance.new("BodyVelocity") Bd .MaxForce = Vector3.new(math.huge, math.huge, math.huge) Bd .Velocity = mp * 100
(This is not the full script as it works if I do not try to make it aim for the mouse position.
local mp = Mouse.Hit.p
This is what it says in the local script that invokes the other scripts.
Vectors have two parts: direction and magnitude. Direction is pretty self explanatory. Magnitude is how big the vector is.
The vectors (0, 1, 0)
and (0, 5, 0)
have the same direction (up), but not the same magnitude (speed of 1 vs speed of 5).
The vectors (0, 1, 0)
and (1, 0, 0)
have the same magnitude (1) but not the same direction (up, and left).
To get the vector going from point A to point B, we do B - A
. If we were to add this to A, we'd get B: (B - A) + A = A
However, this has a magnitude of "the distance from A to B". In other words, if we make our projectile have this speed, it would arrive there instantly.
Therefore, we find something called the "unit vector", which is basically the vector which has the same direction but a magnitude (or speed, in this case) of 1: (B-A).unit
Then, we multiply this unit vector by the speed we want to get a vector going in the correct direction with the correct speed: (B-A).unit * speed
.
function getVector(a, b, speed) return (b - a).unit * speed end
I believe this is the formula, if not, try following the person above, yet I think it's not exactly necessary, give this a shot?
a.CFrame = CFrame.new(a.CFrame.p,mp) Bd.Velocity = a * 100
Hope it works!