Fireball shooting script curves when fired

So I have a script that when you click, a fireball should fire in the direction the player is looking after being welded to the player for 2 seconds, and it works, but if the player is turning when the fireball is shot, the fireball sometimes curves. I am creating a Linear Velocity in script when I fire this. The fireball object only has an attachment for the Linear velocity.

Video of normal vs. curving

Code of firing the ball in the server script.

--References 
local RS = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local TS = game:GetService("TweenService")
--Gets fireball folder
local Folder = RS:WaitForChild("Attacks"):WaitForChild("Spells"):WaitForChild("Fireball")
--Gets fireball remote and mesh object
local Remote = Folder.FireballRemote
local Fireball = Folder.FireballObj
Remote.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	local humrp = char:FindFirstChild("HumanoidRootPart")
    --Creates a VFX folder
	local folder = Instance.new("Folder", plr.Character)
	folder.Name = "FireballFX"
	--Puts the fireball on the player
	local vfx = Fireball:Clone()
	vfx.Parent = folder
	vfx.CFrame = humrp.CFrame
	vfx.Position = humrp.Position
	--Welds the fireball onto the player
	local weld = Instance.new("ManualWeld")
	weld.Name = "VFXWeld"
	weld.Part0 = vfx
	weld.Part1 = humrp
	weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	--Creates the linear velocity
	local velocity = Instance.new("LinearVelocity")
	velocity.Enabled = false
	velocity.Parent = vfx
	velocity.Name = "Velo"
	velocity.MaxForce = 1000000
	velocity.Attachment0 = velocity.Parent:FindFirstChild("Attachment")
	velocity.RelativeTo = 0

	delay(1, function()
         --Kills the weld and enabled the velocity.
		vfx:FindFirstChild(weld.Name):Destroy()
		velocity.Enabled = true
		velocity.VectorVelocity = Vector3.new(0,0,-60)
		Remote:FireClient(plr)
		
		delay(2, function()
			if (not vfx:FindFirstChild("FullCVar")) then
				folder:Destroy()
			end
		end)	
	end)
end)
1 Like

This might be because you’re creating the velocity too soon, I recommend to create the velocity after the weld is removed so that it’ll reflect based on where the player is looking.

	delay(1, function()
         --Kills the weld and enabled the velocity.
		vfx:FindFirstChild(weld.Name):Destroy()

		local velocity = Instance.new("LinearVelocity")
		velocity.Enabled = false
		velocity.Parent = vfx
		velocity.Name = "Velo"
		velocity.MaxForce = 1000000
		velocity.Attachment0 = velocity.Parent:FindFirstChild("Attachment")
		velocity.RelativeTo = 0
		velocity.Enabled = true
		velocity.VectorVelocity = Vector3.new(0,0,-60)

		Remote:FireClient(plr)
		
		delay(2, function()
			if (not vfx:FindFirstChild("FullCVar")) then
				folder:Destroy()
			end
		end)	

Also, as general practice I’d recommend using DebrisService over using :Destroy on a weld.

1 Like

LinearVelocity adds a velocity based on the orientation of the Attachment0, which is glued to the part. However, the part inherits the angular speed of your character, and rotates as a result. The attachment rotates aswell, and so doest the LinearVelocity orientation.

You could either just use BodyVelocity or make LinearVelocity relative to the world.

I feel like this reply is going to work, but can you explain how to convert the direction the player is facing into a world direction?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.