Help on lookvector

  1. What do you want to achieve? I want to make a part to look wherever the player is looking at.

  2. What is the issue? It does face the way I want to , it just looks weird…

  1. I tried setting the position to the lookvector too, didnt work. Did you look for solutions on the Developer Hub?
function module.AddKickPart(player)
	local character = player.Character
	local kickpart = game.ReplicatedStorage.kickpart:Clone()
	kickpart.Parent = workspace
	kickpart.CFrame = CFrame.new(character.HumanoidRootPart.Position) * CFrame.new(0, -3, 0)
	while true do
		wait(0.0001)
		local unit = character.HumanoidRootPart.CFrame.LookVector.Unit
		kickpart.CFrame = CFrame.new(character.HumanoidRootPart.Position) * CFrame.new(0, -2, -1) * CFrame.Angles(unit.X, unit.Y, 0)
	end
end

For the CF kickpart, maybe try the LookAt way

you have to use mouse.Hit.p then use CFrame.lookAt(Part,mouse.Hit.p)

are you overcomplicating things?
if you want to have a part look the same way as the player maybe

try

part.Orientation  = Character.Humanoid.RootPart.Orientation

but if it also need to have the same position

part.CFrame = Character.Humanoid.RootPart.CFrame
function module.AddKickPart(player)
	local character = player.Character
	local kickpart = game.ReplicatedStorage.kickpart:Clone()
	kickpart.Parent = workspace
	kickpart.CFrame = CFrame.new(character.HumanoidRootPart.Position) * CFrame.new(0, -3, 0)
	local rootPart = character.HumanoidRootPart
	while true do
		wait(1/30) -- the limit is 1/30 of a second btw.
		kickpart.CFrame = rootPart.CFrame * CFrame.new(0, -2, -1)
		-- if it is pointing the wrong angle... adjust it using this...
		-- * CFrame.Angles(math.rad(90),0,0) -- adjust this as neccesary and put it after the cframe.new
	end
end

CFrames can be a little bit wonky to work out sometimes, but they have a definite logic to them.

part.CFrame
-returns the Position and LookVector (point direction) of part

part.CFrame = part.CFrame * CFrame.new(0, 1, 0)
-offsets the position by 1 stud on the Y Axis relative to the Part’s LookVector

part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(45), 0)
-Rotates the cframe by a certain amount of degrees (using math.rad())

You can stack these adjustments on top of each other as well - as the next CFrame transformation will be relative to the last.

part.CFrame = part.CFrame * CFrame.new(0,1,0) * CFrame.Angles(math.rad(180),0,0) * CFrame.new(0,1,0) * CFrame.Angles(math.rad(180),0,0)
-literally the same position/rotation as started.

You can also imagine rotation like a plane.

part.CFrame = part.CFrame * CFrame.Angles(math.rad(45),0,0)
-will pitch the plane upwards at a 45 degree angle relative to the existing part’s cframe

1 Like