I’ve been trying to make a projectile weapon system using raycasts and tweenservice, however my projectile is always a little offset from the mouse.
robloxapp-20230912-1243463.wmv (700.7 KB)
Here’s my code:
local Tool = script.Parent
local Mouse = Player:GetMouse()
Mouse.Button1Down:Connect(function()
local Origin = Tool:FindFirstChild('Handle')
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances= {Player.Character}
RayParams.FilterType = Enum.RaycastFilterType.Exclude
local RaycastResult = workspace:Raycast(Origin.Position, Mouse.UnitRay.Direction * 100, RayParams)
if RaycastResult then
local BulletClone = Bullet:Clone()
BulletClone.CFrame = CFrame.new(Origin.Position, Mouse.UnitRay.Direction * 100)
BulletClone.Parent = workspace
local RayTween = TweenService:Create(BulletClone, tweenInfo, {Position = RaycastResult.Position})
RayTween:Play()