Won't shoot projectile exactly to the mouse position

What do you want to achieve?
I want the projectile to shoot exactly to the mouse position, I don’t want it to shoot near it. And I wanna understand why it does that.

What is the issue?
It doesn’t shoot exactly on it, I want to fix it.

image

What solutions have you tried so far?
I’ve looked up how to make the projectile shoot on mouse position but it doesn’t shoot to its exact position.

Local Script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local rs = game:GetService("ReplicatedStorage")
local bally = rs:WaitForChild("Bally")
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gameprocessed)
	if gameprocessed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
	
		script.Fire:FireServer(bally, mouse.Hit.p)
		
	end
end)

Server Script

local speed = 10
local damage = 20
local lifetime = 10

local cooldown = 1
local canshoot = true
local debris = game:GetService("Debris")

script.Parent.Fire.OnServerEvent:Connect(function(player, bally, mousePos)
	if not canshoot then return end
	
	canshoot = true
	
	local char = player.Character
	if not char then
		return
	end
	
	local root = char:FindFirstChild("HumanoidRootPart")
	
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(1,1,1) * 30000
	bv.Velocity = mousePos * speed
	
	local cally = bally:Clone()
	cally.Parent = workspace
	cally.CFrame  = root.CFrame
	bv.Parent = cally
	
	debris:AddItem(cally, lifetime)
	
end)

Also if you can, I don’t quite understand the BodyVelocity.MaxForce and I’ve searched up it but I still don’t understand. I don’t get why you have to have it be 30000 bv.MaxForce = Vector3.new(1,1,1) * 30000, so if you could explain that to me, that’d be great. And if you’re wondering why I don’t understand it if I typed it then it’s because I was following a tutorial on youtube.

2 Likes

What I do to shoot a projectile to a specific mouse position hit. Is getting a CFrame look vector relative to the projectile and the mouse position, like this:

bv.Velocity = CFrame.new(cally.Position, mousePos).LookVector * speed

The ball should go exactly where the mouse is aiming relative to its current position
Just dont call that before local cally is created of course.

And the bv.MaxForce = Vector3.new(1,1,1) * 30000 Its just the MaxForce that the bodyVelocity will have. You can see that parameters if u create a bodyVelocity in studio and check. Try to reduce the force and watch the differences

You can check more documentation/info in the Hub
image
https://developer.roblox.com/en-us/api-reference/class/BodyVelocity

4 Likes