✓ Accepted answer
If this translates poorly, please let me know, so I can change my wording.
local Speed = 100
local BulletSize = Vector3.new(0.5,0.5,2)
script.RemoteEvent.OnServerEvent:connect(function(plr,Pos)
local Origin = script.Parent.Handle.CFrame.Position
local Bul = Instance.new("Part")
local bod = Instance.new("BodyVelocity")
Bul.Size = BulletSize
Bul.Material = ("Neon")
Bul.CFrame = CFrame.new(Origin,Pos) * CFrame.new(0,0,-1)
bod.Velocity = (Pos - Origin).Unit*Speed
bod.Parent = Bul
Bul.Parent = workspace
end)
So the velocity vector is made up of two components: Speed and direction. You can view it as a direction vector multiplied by the speed you want the bullet to travel. In order to get the direction vector, you need to know the starting point and the "Pos" and apply the .Unit function to the difference between the two. Then you can multiply that by the Speed to get your completed Velocity vector.
I also want to note that you should set all other properties (including everything done with the BodyVelocity) before parenting the bullet to the workspace because it will reduce possible lag.
9 comments
Sorry, maybe I missed something, I just never worked with Velocity. But when I started testing, the bullet just appeared without moving.
Let me actually write this in studio, I might've missed something myself.
If necessary, here is the activation of Event: TOOL.Activated:Connect(function() RemoteEvent:FireServer(Mouse.hit.p) end) its local script
It was a simple error on my end, I shouldn't have made a new vector from their subtraction.
Ugh. Error in 08. "attempt to multiply a Vector3 with an incompatible value type or nil"
Oh woops, made another simple mistake, I am confident it is fixed now.
Thanks, it works. But the bullet does not look towards pos when it flies. I know that I need to do something with the angle. I have no idea what exactly needs to be done.
Ok I can help with that too
All you need to do is set a position to lookAt on line 11 when the new CFrame is created.