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.
- X = Pitch
- Y = Yaw
- Z = Roll
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