I've been having trouble with my game in that sometimes when a projectile fires it will go in a random direction instead of where my mouse is pointing.
Edit: The camera is forced in its position in the example of what's happening, I'm not sure if that changes anything.
This is the local script
mouseDown = false
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(function()
mouseDown = true
local Char = game.Players.LocalPlayer.Character
local trigger = Char:FindFirstChild("MouseDown")
print(trigger)
print(Char)
repeat
print("Mouse down")
trigger:FireServer(Mouse.Hit.p)
print("Trigger fired")
wait()
until mouseDown == false
end)
Mouse.Button1Up:Connect(function()
mouseDown = false
end)
This is the server script
local event = script.Parent.MouseDown
local cd = .1
local waiting = false
print("event")
event.OnServerEvent:Connect(function(plr,pos)
if not waiting then
waiting = true
local part = Instance.new("Part")
part.Position = pos
local proj = Instance.new("Part")
proj.Size = Vector3.new(1,1,4)
proj.BrickColor = BrickColor.new("Royal purple")
proj.Material = "Neon"
proj.CanCollide = false
proj.Anchored = false
proj.Position = script.Parent.HumanoidRootPart.Position
local bf = Instance.new("BodyForce")
bf.Force = Vector3.new(0, workspace.Gravity * proj:GetMass(), 0)
bf.Parent = proj
proj.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position,Vector3.new(part.Position.X,script.Parent.HumanoidRootPart.Position.Y,part.Position.Z))
bf = Instance.new("BodyVelocity")
bf.Velocity = proj.CFrame.lookVector * 50
bf.Parent = proj
game.Debris:AddItem(proj,2)
proj.Parent = workspace
wait(cd)
waiting = false
end
end)

5 comments
It still appears to go in the wrong direction occasionally. I doubt this changes anything but I'm play testing in studio
hmmm, I have tested your code myself, and while it's not as severe as yours. I have tried adding a .Unit to the bf.Velocity = proj.CFrame.lookvector and it seems like it was fixed. Let me know if it's fixed.
So, proj.CFrame.LookVector.Unit * 50? If that's what you meant then it doesn't seem to have fixed the issue unfortunately.
Exactly what I meant. After a lot of debugging, I came with my final conclusion and it's that, it's the input. I have tested it with what I thought was a completely frozen mouse but turned out not to be and it had very tiny differences in values which got bigger when used as a projectile.
What I recommend you to do, is to instead (just for testing) bind the function to a keyboard key and leave the mouse completely unmoved, the input should be the same and thus same projectile direction etc. If not then unfortunately, that's how far I can try to help. I hope you find the solution :D