Trouble with direction of cannon fire

So with some help on my script, I have created a cannon that fires a cannon ball. However, my problem is that it only fires one way, no matter which way you are facing:

local somePart = Instance.new("Part")
			somePart.Shape = Enum.PartType.Ball
			somePart.Size = Vector3.new(0.91, 0.91, 0.91)
			somePart.Parent = game.Workspace
			somePart.Position = script.Parent.Handle.Position
			
			local bodyVelocity = Instance.new("BodyVelocity")
			bodyVelocity.Parent = somePart

			local speed = 50

			local Distance = (script.Parent.Handle.CFrame.LookVector * 30 - somePart.Position).Magnitude

			bodyVelocity.Velocity = (somePart.CFrame.LookVector * speed)

			wait(Distance/speed)

			bodyVelocity:Destroy()
			
			somePart.Touched:Connect(function(hit)
				if hit:IsA("BasePart") then
					somePart:Destroy()
				end

Any help?

2 Likes

Could you show a screenshot since I can’t view the video and show the code you used.

Can you please show the code? Also, I am guessing this is from you not taking into account the LookVector.

Oh yes, of course! Sorry, be right with you…

if u are using Mouse then u should calculate the direction

local Direction = (HumanoidRootPart.Position - Mouse.Hit.P).unit * 100 – Thats for ray casting

else

CannonBall.Velocity = HumanoidRootPart.CFrame.LookVector * 60 -- speed`
1 Like

u have just to change BodyVelocity and remove the old one like that

local BV = instance.new("BodyVelocity", somePart)
BV.Velocity = (HumanoidRootPart.CFrame.LookVEctor * 60)
BV.MaxForce = Vector3.new(4000,4000,400)
3 Likes

You do not need to use a distance variable.

Like @kalabgs said change it to this

The reason why it is not going the front direction is because you used the look vector of the somepart instead of the tool’s handle which is moving the part towards the look vector of the ball.

local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = somePart
local speed = 50
BodyVelocity.MaxForce = (math.huge,math.huge,math.huge)
BodyVelocity.Velocity = script.Parent.Handle.CFrame.LookVector * speed