How do I get the Bul to fly towards Pos at a certain speed?
script.RemoteEvent.OnServerEvent:connect(function(plr,Pos) local Bul = Instance.new("Part") Bul.Parent = game.Workspace Bul.Size = Vector3.new(0.5,0.5,2) Bul.Material = ("Neon") Bul.CFrame = script.Parent.Handle.CFrame * CFrame.new(0,0,-1) local bod = Instance.new("BodyVelocity") bod.Parent = Bul Bul.BodyVelocity.Velocity = Vector3.new(Pos) end)
p.s. sorry for my english, im use google translate :)
If this translates poorly, please let me know, so I can change my wording.
--if this won't change, then set it outside of the function 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.