I’m currently working on a hockey game and on the shot part, the puck doesn’t actually go where the mouse is unless the character and mouse are facing the same direction, is there any way I can fix this to make it go where the mouse is and not need the character to be looking there as well (Using applyimpulse) Code Below
script.Parent.Equipped:Connect(function()
script.Parent.SE.OnServerEvent:Connect(function(plr,power,mhp, mhv) -- Player, Power of shot (25-100), Mouse Hit Position, Mouse HitVector
print(power)
local bg = Instance.new("BodyGyro")
local ps1 = game.Workspace.ShotS
local ps2 = game.Workspace.ShotB
bg.Parent = game.Workspace.Puck
bg.P = 100000000000
bg.D = 10000000000000
bg.MaxTorque = Vector3.new(999999999999999999,99999999999999999,999999999999999)
bg.CFrame = CFrame.Angles(0,0,-90)
game.Workspace.Puck.Canpick.Value = false
game.Workspace.Puck:FindFirstChild("Attatched"):Destroy()
local lesspower = power / 6
local lesspower2 = power / 15
game.Workspace.Puck.CFrame = CFrame.lookAt(game.Workspace.Puck.Position, mhv)
game.Workspace.Puck.CanCollide = true
local bv = Instance.new("BodyVelocity") -- Controls The Shot's Height Not Direction (I tested it)
bv.Parent = game.Workspace.Puck
bv.Velocity = Vector3.new(0,lesspower,0)
bv.P = 100000000
bv.MaxForce = Vector3.new(0,1001010,0)
local impulse = game.Workspace.Puck:ApplyImpulse(Vector3.new(mhv.X * lesspower,lesspower2, mhv.Z * lesspower)) -- Controls Where The Shot Goes
game:GetService("Debris"):AddItem(impulse, power/75)
game:GetService("Debris"):AddItem(bv, power/150)
local random = math.random(1,2)
if random == 1 then
ps1:Play()
elseif random == 2 then
ps2:Play()
print("2")
end
game:GetService("Debris"):AddItem(bg, power/50)
game.Workspace.Puck.GoalScorer.Value = plr.Name
wait(.7)
game.Workspace.Puck.Canpick.Value = true
end)
end)