-
Orientation facing right direction, forward in direction it goes, like any direction
-
Orientation ends up facing left as object is sent flying in direction of mouse.position while it supposed to only face forward the direction it is sent flying in the direction of the Mouse.Position .
function module:Fire(params)
local player = params.player
local char = params.char
local humrp, hum = params.root, params.hum
local MouseHit = params.mousehit
local mousepos = MouseHit.Position
local cooldown = params.cooldown
local rightarm = params.rightarm
local spear = script.Spear:Clone()
spear.Size = Vector3.new(4, 2, 14)
spear.Parent = workspace.Debris
-- Calculate direction to mouse position
local startPos = rightarm.Position
local direction = (mousepos - startPos).unit
-- Set the spear's position to the start position, but keep it upright
spear.CFrame = CFrame.new(startPos, startPos + humrp.CFrame.LookVector) * CFrame.Angles(math.rad(90), 0, 0)
spear.Anchored = false
local TweenProjectileTrans = ts:Create(spear, TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 0})
TweenProjectileTrans:Play()
local tween = ts:Create(spear, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = Vector3.new(12.96, 1.434, 4.722)})
tween:Play()
local bvel = Instance.new("BodyVelocity", spear)
bvel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bvel.Velocity = direction * 145
local check
check = game:GetService("RunService").Heartbeat:Connect(function()
local hit, position = workspace:FindPartOnRayWithWhitelist(Ray.new(spear.Position, direction * 10), {game.Workspace.Debris})
if hit and hit:IsA("BasePart") then
local cf = CFrame.new(position)
spear.CFrame = cf * CFrame.Angles(0, math.rad(90), 0) -- Keep the spear upright when it hits something
spear.BodyVelocity.Velocity = Vector3.new(0, 0.1, 0)
spear.Anchored = true
local tween = ts:Create(spear, TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = Vector3.new(25, 25, 25), Transparency = 0})
tween:Play()
check:Disconnect()
end
end)
end