Object projectile from player character is facing

Ok, Hello everyone I would like to know how do I make the part projectile from your character face orientation. (Third Person)

This the example of the code in simplified version:

--local cooldown = 22
--local cooldowns = {}

--game.ReplicatedStorage.Server.ChainsawRE.SlashRE.OnServerEvent:Connect(function(plr, hit, tap1)
	--if cooldowns[plr] or not hit then return end
	--cooldowns[plr] = true
	
	--------XYZ
	local x = 6.586
	local y = plr.Character.PrimaryPart.Orientation.Y
	
	--local chain = game.ServerStorage.Ability.ChainSawParts["lft part"]:Clone()	
	--chain.DP:Destroy() chain.Part:Destroy() chain.Motor6D:Destroy()
	
	chain.CFrame = CFrame.fromEulerAnglesXYZ(x,y,0)
	chain.Size = Vector3.new(1.918, 10.156, 38.507)
	chain.Anchored = true chain.CanCollide = false
	
	chain.Parent = workspace
	chain.Position = plr.Character.PrimaryPart.Position
	
	--local point = Instance.new("Part")
	--point.Parent = workspace
	
	--point.Anchored = true point.CanCollide = false
	--point.Transparency = 1
	point.CFrame = CFrame.fromEulerAnglesXYZ(x,y,0)
	point.Position = chain.Position + Vector3.new(-156,0,156)
	
    --- Create a movement forward (limted for few second) the player character is facing currently 
	local ts = game:GetService("TweenService")
	local move = ts:Create(chain, TweenInfo.new(1.1), {Position =  point.Position})
	move:Play()
	
	--wait(3)
	--point:Destroy() chain:Destroy()
	--cooldowns[plr] = nil
end)

The highlighted one is the Problem toward the ideal functions

Here’s the illustration for the explanation


CONTEXT: after the output from player the script will lunch a object from the player, move toward the player facing if amount of time the part will be deleted.

I greatly appreciate and thankful for the help

1 Like

so you want to shoot an object where the player is looking?
you can calculate the direction for the projectile by using (humanoid.TargetPoint - humanoidrootpart.position).Unit * power i think or use the humanoidrootPart.CFrame.LookVector

1 Like

There’s a lot of tutorials on YouTube about this, just search up “Roblox Studio Fireball Ability”.

I also recommend getting the CFrame of the HumanoidRootPart, it’d look like:
Character.HumanoidRootPart.CFrame.LookVector


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, hit)
	if cooldowns[plr] or not hit then return end
	cooldowns[plr] = true
	--------XYZ
	local x = 6.586
	local y = plr.Character.PrimaryPart.Orientation.Y

	local chain = game.ServerStorage.Part:Clone()

	chain.CFrame = CFrame.fromEulerAnglesXYZ(x,y,0)
	chain.Size = Vector3.new(1.918, 10.156, 38.507)
	chain.Anchored = true chain.CanCollide = false

	chain.Parent = workspace
	chain.Position = plr.Character.PrimaryPart.Position

	local ts = game:GetService("TweenService")
	local move = ts:Create(chain, TweenInfo.new(1.1), {Position =  plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector})
	move:Play()
	
	cooldowns[plr] = false
end)

The part move toward the (vector = 0,0,0) and not toward the player is facing to.

you are making a weapon like a bazooka or something?

The look vector is a unit vector, which means it’s on a scale of [-1, 1] for each coordinate with a guaranteed magnitude of 1 (or it’ll be a nan value but that doesn’t apply in our case)

What you would want to do is translate the current CFrame by the LookVector (with a multiplied magnitude for how far you want it to go)

local Distance = 10 -- 10 Studs of max distance
local TargetPart = workspace.Part -- Make this your projectile
local RootPart = game.Players.LocalPlayer.Character.HumanoidRootPart -- Caster character's root part
local EndCFrame = RootPart.CFrame * CFrame.new(RootPart.CFrame.LookVector*Distance) -- "Adds" the new direction to the current CFrame
TargetPart.CFrame = EndCFrame -- Sets the part's cframe, change this to a tween at your will

(note: if you reply, I won’t be able to respond for a while)