I understand it much better. Thanks. But what other things can I do with CFrame other than Position and Orientation?
CFrame is basically just Vector3, EXPECT that Vector3 doesn’t have orientation built in, CFrame does. That’s the only difference between Vector3 and CFrame.
And I forgot; if you want to add another Position to it, in Vector3 you would do Vector3.new(firstPosition) + Vector3.new(secondPosition), in CFrame you would do CFrame.new(firstPosition) * CFrame.new(secondPosition)
So if I want to change a part’s orientation. Would I do:
local part = game.Workspace.Part
part.Oriention = Vector3(445, 3, 44) -- Orientation
Or Would I do:
local part = game.Workspace.Part
part.CFrame *= CFrame.Angles(0, math.rad(90), math.rad(90))
Both are the same, expect that I think Orientation is Vector3.new(Z, Y, X) and CFrame.Angles is CFrame.Angles(X, Y, Z)
Oof the information I gave you was wrong, Orientation is applied in Y-X-Z and CFrame.Angles is Applied on Z-Y-X
A common use myself for CFrame is pointing a part towards an object. You can do this by something like this: part1.CFrame = CFrame.new(part1.Position,part2.Position)
(this will point part1 towards part2)
That’s deprecated. You have to use lookAt(). Example:
local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2
part1.CFrame = CFrame.lookAt(part1.Position, part2.Position) -- Vector3 what should be looked at, Vector3 Target
It isn’t marked as deprecated tho, but yeah lookAt should be used
Thanks so much!!! So what about RayCasting?
Raycasting in a nutshell is just that it just creates an invisible line from the point it starts to its direction
For example if we did workspace:Raycast(Vector3.new(), Vector3.new(0, 5, 0))
it would make an invisible line starting from Vector3.new(0, 0, 0) going to Vector3.new(0, 5, 0)
And if from Vector3.new(0, 0, 0) to Vector3.new(0, 5, 0) it hit something that isn’t in blacklist/is in whitelist then it is going to stop the ray and return the rayInformation
Ok, I think I understand. Does this work?
local rCP = RaycastParams.new()
rCP.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
rCP.FilterType = Enum.RaycastFilterType.Blacklist
local result = game.Workspace:Raycast(Vector3.new(100, 0, 100), Vector3.new(100, 100, 0), rCP)
if result and result.Instance.Parent:FindFirstChild("Humanoid") then
result.Instance.Parent:FindFirstChild("Humanoid").Health = 0
end
I think so, you gotta test it out to see if it works tho
But you would need to cast the ray in a while loop or something cuz the line doesn’t stay forever
And you also need to remove the local player from blacklist or it won’t detect him
So I will do white list. Thanks
Yeah that would be fine with whitelist
Yeah doesn’t work.
local a = game.Workspace.A -- This is a part called A
while wait() do
local result = game.Workspace:Raycast(a.CFrame.LookVector, Vector3.new(100,0,0))
if result and result.Instance.Parent:FindFirstChild("Humanoid") then
result.Instance.Parent:FindFirstChild("Humanoid").Health = 0
end
end