Hey There. I was working on a fireball projectile for a 2d game and i didnt know how to make it appear in front of the player.I Used ToWorldSpace Function But It Followed The Mouse Pointer Instead.The 2 Ways The Player Would Move Will Be Left And Right So I need the Firball to move in the direction of the player
if you need a video of what i mean ill gladly give it to you
does that mean that you could just check if they are left or right and then put it in front of then in relation to that
eg.
local player = game.Players.LocalPlayer
local projectile
local function fireprojectile()
if player.Torso.Orientation.X = 90 then
--make the rocket face right (or left, depending on what your working with.)
else
--make the rocket face left (or right, depending on what your working with.)
end
end
also, a video would be nice to see how the rotation works (for shooting while your turning)
Yes , It depends On the Side They Are Looking
Ill give you a video right away
Wait wait wait Ill first Show you the scripts made…
Also i think the problem is used the GetMouse Function
Local Script in Starter Player Scripts
local UIS = game:GetService(“UserInputService”)
local RS = game:GetService(“ReplicatedStorage”)
local Deb = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Q and not Deb then
Deb = true
RS.FireBallEvent:FireServer(game.Players.LocalPlayer:GetMouse().Hit.p)
wait(2)
Deb = false
end
end)
And ServerScript Service For the remote event
local Speed = 100
local Length = 1
local Damage = 15
local RS = game:GetService(“ReplicatedStorage”)
RS.FireBallEvent.OnServerEvent:Connect(function(plr, HitPos)
if plr and plr.Character and plr.Character.PrimaryPart and plr.Character:FindFirstChild(“Humanoid”) then
local Clone = RS.Fireball:Clone()
Clone.Parent = workspace
Clone.Position = plr.Character.PrimaryPart.CFrame:ToWorldSpace(Vector3.new(0,0,-5))
local BV = Instance.new("BodyVelocity", Clone)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.P = math.huge
BV.Velocity = CFrame.new(Clone.Position,HitPos).LookVector * Speed
local Deb = {}
Clone.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if not table.find(Deb, Hit.Parent.Humanoid) and Hit.Parent.Humanoid ~= plr.Character:FindFirstChild("Humanoid") then
table.insert(Deb, Hit.Parent.Humanoid)
game.Debris:AddItem(Clone,.2)
Hit.Parent.Humanoid:TakeDamage(Damage)
end
end
end)
game.Debris:AddItem(Clone, Length)
end
end)
Get mouse is used for getting the position / thing that if you were looking from the cameras view would be where you think that you mouse would “touching”
by the way, GetMouse() can only be used on local scripts. using it on server scripts just doesn’t make sense because the server is not a player and does not have a mouse.
It is used on a local script…