How to increase size and position in the direct of the HumanoidRootPart's orientation?

Hello, Im currently looking to increase the size and position of my part, but only in the direction of where the player is looking. Sort of to make an increasing energy wave. Ive tried alot of things but none seem to work, any suggestions?
Here is the script, and a video of what its currently doing.

video:

script:

local charge = game.ServerStorage:WaitForChild("KameCharge")
local wave = game.ServerStorage:WaitForChild("KameWave")
local ts = game:GetService("TweenService")


--tween

local info = TweenInfo.new(
	3,
	Enum.EasingStyle.Cubic,
	Enum.EasingDirection.Out,
	1,
	false,
	0.1
)



local GoalTransparency = {
	Transparency = 1
}





game.ReplicatedStorage.Kamehameha.OnServerEvent:Connect(function(player, MousePos)
	local character = player.Character
	local humanoid = character.HumanoidRootPart
	local rarm = character:FindFirstChild("Right Arm")
	
	local newcharge = charge:Clone()
	newcharge.Parent = rarm 
	newcharge.Position = rarm.Position - Vector3.new(0, 1, 0)
	
	
	local Weld = Instance.new("WeldConstraint")
	Weld.Parent = newcharge
	Weld.Part0 = rarm
	Weld.Part1 = newcharge
	
	wait(1)
	
	newcharge:Destroy()
	
	local newwave = wave:Clone()
	newwave.Parent = workspace
	newwave.Position = character.Torso.Position + Vector3.new(2,0,0)
	newwave.Orientation = character.Torso.Orientation
	local goal = {
		Size = Vector3.new(7, 7, 180),
		Position = character.Torso.Position + Vector3.new(0,0,90)
	}
	
	local tween = ts:Create(newwave, info, goal)
	tween:play()

	
end)

CFrame.LookVector
https://developer.roblox.com/en-us/api-reference/datatype/CFrame

Vector3 CFrame.LookVector
The forward-direction component of the CFrame’s orientation. Equivalent to: Vector3.new(-r20, -r21, -r22).

Adding a CFrame’s LookVector to itself would produce a CFrame moved forward in whichever direction the CFrame is facing by 1 unit:

cf = cf + cf.LookVector * n -- Move cf forward n units

It’s important to break down what you want to do into very simple components; I’ve found it to be a great approach when making visual effects

-- modulescript

local function Tween(Object : Instance, Properties : Dictionary<any>, Time : number, ...) -- handy tween function
	game:GetService("TweenService"):Create(Object, TweenInfo.new(Time, ...), Properties):Play()
end

local module = {}

function module.CastBeam(Origin : Vector3, Goal : Vector3, Velocity : number, Size : Vector3)
	local FlatSize = Size * Vector3.new(1, 1, 0) -- preserve x, y components
	local NewBeam = Instance.new("Part")
	NewBeam.Anchored = true
	NewBeam.CastShadow = false
	NewBeam.CanCollide = false
	NewBeam.Material = Enum.Material.Neon
	NewBeam.Size = FlatSize
	NewBeam.CFrame = CFrame.lookAt(Origin, Goal)
	NewBeam.Parent = workspace

	local Distance = (Goal - Origin).Magnitude
	local TweenTime = Distance / Velocity
	local Midpoint = Goal:Lerp(Origin, 0.5)

	Tween(NewBeam, {
		Position = Midpoint;
		Size = FlatSize + Vector3.new(0, 0, Distance)
	}, TweenTime)
	
	task.spawn(function()
		task.wait(TweenTime)
		NewBeam:Destroy()
	end)
end

return module
-- localscript
local BeamMaker		= require(script:WaitForChild("ModuleScript"))

local Player		= game:GetService("Players").LocalPlayer
local Character		= Player.Character or Player.CharacterAdded:Wait()
local RootPart		= Character:WaitForChild("HumanoidRootPart")

game:GetService("UserInputService").InputBegan:Connect(function(i, o)
	if o then return end
	if i.KeyCode == Enum.KeyCode.Q then
		BeamMaker.CastBeam(RootPart.Position, (RootPart.CFrame * CFrame.new(0, 0, -100)).Position, 50, Vector3.new(5, 5, 0))
	end
end)
1 Like