Does anyone know why the projectile is not going in the right direction of the mouse? I already looked for help in several places, but I didn’t find it …
What I want is for the projectile to go in the right direction of the mouse, like this:
He needs to leave the HumanoidRootPart
Position and follow the direction of the mouse.
Sorry for the video crashing…
Local Script:
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local chr = player.Character
local Mouse = player:GetMouse()
local ButtonDown = false
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E then
ButtonDown = true
local BP = Instance.new("BodyPosition", chr.HumanoidRootPart)
BP.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BP.Position = chr.HumanoidRootPart.Position
local BG = Instance.new("BodyGyro", chr.HumanoidRootPart)
BG.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
BG.P = 25000
while ButtonDown == true do
BG.CFrame = CFrame.new(chr.HumanoidRootPart.Position, Mouse.hit.p)
RS.Heartbeat:Wait()
end
wait(0.5)
BP:Destroy()
BG:Destroy()
end
end)
UIS.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E then
ButtonDown = false
script.Function:FireServer(Mouse.hit.p)
end
end)
Server Script
script.Parent.OnServerEvent:Connect(function(plr, mousePos)
local Ball = game.ReplicatedStorage.TestBall:Clone()
Ball.Parent = game.Workspace
Ball.CFrame = CFrame.lookAt(plr.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,4).p, mousePos)*CFrame.Angles(0,math.rad(0),0)
Ball:SetNetworkOwner(plr)
local BV = Instance.new("BodyVelocity",Ball)
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Velocity = CFrame.new(plr.Character.HumanoidRootPart.Position, mousePos).lookVector*120
end)
Thanks for any help!