I’m trying to create a bow tool for practice, and I’m having two issues.
My biggest issue is that the projectile flies directly forwards from the player instead of towards the mouse position, a secondary issue is that depending on how far away from the character I click the speed increases or decreases.
Any help is appreciated
Local Script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
script.Parent.Shoot:FireServer(mouse.Hit.p)
print("done")
end)
Tool Script:
local debounce = false
local direction
local debris = game:GetService("Debris")
local replicatedstorage = game:GetService("ReplicatedStorage")
--Getting mouse position when player clicks
script.Parent.Shoot.OnServerEvent:Connect(function(player, mousePos)
direction = mousePos
end)
--Changing the grip when equipped
script.Parent.Equipped:Connect(function()
script.Parent.GripPos = Vector3.new(0,0,0)
end)
script.Parent.Activated:Connect(function(player)
if not debounce then
debounce = true
--add animation eventually
--wait function of some sort needed to make the animation and action appear connected
local arrow = replicatedstorage.Projectiles.Arrow:Clone() --cloning arrow object to be the projectile launched by bow
arrow.Parent = workspace
arrow.CFrame = script.Parent.Handle.CFrame
print("1")
--Velocity of the arrow
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(1e8, 1e8, 1e8)
bv.P = 0 --this is the "aggression" of the force used to reach the max speed, play with this variable.
bv.Velocity = direction * 10
bv.Parent = arrow
debounce = false
print("2")
end
end)
Video of what I described
Place file:
Bow Scripting.rbxl (30.9 KB)