When the attacker throws the object, I want it to stay the same orientation as when its thrown so it doesn’t spin when it lands.
script: (room is thrown object)
local x, y, z = room.CFrame:ToOrientation()
local AlignOrient = Instance.new("AlignOrientation")
AlignOrient.Attachment0 = room.Main
AlignOrient.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignOrient.CFrame = CFrame.Angles(x, y, z)
AlignOrient.Parent = room
The AlignOrientation gets created & parented to the room but Its CFrame Orientation is (0,0,0). The output has no errors & the script analysis isn’t saying something is weird.
Try printing out the result from :ToOrientation(), are they the right angles?
As a side note, the rotation order of :ToOrientation() is applied in YXZ order, but CFrame.Angles() applies rotation in XYZ order, so you should use either CFrame.fromOrientation() or CFrame.fromEulerAnglesYXZ() instead.
This is the throw part of the skill remote OnServerEvent
lawSkillRemote.OnServerEvent:Connect(function(plr)
if plr.Character == char then
if char:GetAttribute("CanThrow") == true and char:GetAttribute("Attacked") == false then
char:SetAttribute("CanThrow", false)
script.RoomExists.Value = true
room = ss.Law.Room10:Clone()
room.Parent = workspace[tostring(plr.UserId)]
local y, x, z = room.CFrame:ToOrientation()
print(y, x, z)
local AlignOrient = Instance.new("AlignOrientation")
AlignOrient.Attachment0 = room.Main
AlignOrient.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignOrient.CFrame = CFrame.fromOrientation(y, x, z)
AlignOrient.Parent = room
room:SetNetworkOwner(plr)
script.Parent:SetAttribute("RoomThrown", true)
-- anchor room (hit obiect)
local roomStopped = false
task.spawn(function()
repeat
for i,v in workspace:GetPartBoundsInBox(room.Center.CFrame, Vector3.new(1.5,1.5,1.5), OverlapParams.new()) do
if v.Name == "Baseplate" then
local liv = Instance.new("LinearVelocity")
liv.MaxForce = math.huge
liv.VectorVelocity = Vector3.new(0,0,0)
liv.Attachment0 = room.Main
liv.Parent = room
roomStopped = true
end
end
task.wait()
until roomStopped == true
end)
-- anchor room (hit ground)
local connection
connection = runService.Heartbeat:Connect(function(deltaTime)
if roomStopped == true then connection:Disconnect() end
if room.Center.Position.Y <= 2 then
local liv = Instance.new("LinearVelocity")
liv.MaxForce = math.huge
liv.VectorVelocity = Vector3.new(0,0,0)
liv.Attachment0 = room.Main
liv.Parent = room
roomStopped = true
connection:Disconnect()
end
end)
-- hitbox overlap params
local params = OverlapParams.new()
params.FilterDescendantsInstances = {char.Hitbox}
params.FilterType = Enum.RaycastFilterType.Exclude
repeat
for i,v in workspace:GetPartBoundsInRadius(room.Position, 3.3, params) do
if v.Name == "Hitbox" then
params:AddToFilter(v)
attackedB:Fire(v.Parent, plr.UserId, 5)
knockbackB:Fire() -- TODO knockback
end
end
task.wait()
until roomStopped == true
-- get big
for i = 1, 13 do
room.Size += Vector3.new(1.5,1.5,1.5)
task.wait()
end
room.Main.Slash1.Enabled = true
char:SetAttribute("CanTeleport", true)
Is the CFrame of the room being set before you get its orientation? It seems to me that you create it and then immediately get the orientation before it can rotate, causing an angle of 0, 0, 0
Since it’s giving you an angle, try enabling rigidity on the align orientation.
Also, small tangent regarding rotation order
Rotation order isn’t the return/parameter order of the function, it’s the order in which each axis is rotated. In the case of YXZ, first the Y rotation is applied, then the X rotation , and then the Z rotation. Each axis is influenced by the last.
I will apply a rotation of (45, 30, 0) to this red part in the YXZ rotation order.
I thought it wasn’t working because the character (which faces the same direction as the room when teleporting) was facing the wrong direction most of the time. The wall was pushing the character.
Tysm for the help! I learned a lot from the replies
As @nkmisoup mentioned, you should use CFrame.fromOrientation() instead, but the reason I am writing this reply is because you don’t even need to use Orientation.
You can simply do AlignOrient.CFrame = room.CFrame, and the AlignOrientation will take the orientation of the room’s CFrame (at that time). Note that AlignOrientation ignores the position of the CFrame, it only uses the Rotation
The object spinning is not caused by the AlignOrientation’s CFrame being wrong. It would have to be updated each frame to get it to spin, as AlignOrientation has 1 static target orientation. My guess is that the issue is either the force of the AlignOrientation is too low, or it is not properly set, and thus not acting upon the object