Skip to content
The Chat Archive
gpt-4o-2024-05-13· OpenAI WildChat-4.8M (AI2)

local position = CFrame.new(0, 0, 0) local orientation = CFrame.Angles(math.rad(-90),…

  1. User

    local position = CFrame.new(0, 0, 0) local orientation = CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0)) local combinedCFrame = position * orientation

    print(combinedCFrame)

  2. Assistant

    In Roblox, the concept of CFrame (Coordinate Frame) is used to represent both position and orientation in 3D space. The CFrame.new constructor is used to create a CFrame with a specific position, and CFrame.Angles is used to create a CFrame with specific rotation angles (in radians).

    When you multiply two CFrame objects, the resulting CFrame combines the position and orientation of both. In your case, the position is (0, 0, 0) and the orientation is specified by the angles -90 degrees in the X-axis, -180 degrees in the Y-axis, and 0 degrees in the Z-axis.

    Here is the Lua script snippet you provided:

    local position = CFrame.new(0, 0, 0)
    local orientation = CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0))
    local combinedCFrame = position * orientation
    
    print(combinedCFrame)
    

    This code creates two CFrame instances, one for the position and one for the orientation, then combines them by multiplication. The combined CFrame now holds both the zero position and the specified orientation.

    When you print a CFrame, it outputs the internal matrix representation, which will look something like this:

    CFrame.new(
      -1, 0, 0, 
      0, 0, -1,
      0, 1, 0,
      0, 0, 0
    )
    

    Let's break down what you have:

    • CFrame.new(0, 0, 0) creates a CFrame at the origin.
    • CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0)) creates a rotational CFrame.

    The product of the position CFrame and the angle CFrame will result in a new CFrame that combines both transformations.

    When you look at the printed output, the combined CFrame consists of a 4x4 matrix where:

    • The first three columns are the rotation matrix.
    • The last column is the position vector.

    Considering the provided angles:

    • -90 degrees (or -π/2 radians) rotation about the X-axis.
    • -180 degrees (or -π radians) rotation about the Y-axis.
    • 0 degrees (or 0 radians) rotation about the Z-axis.

    The matrix might indeed come out as:

    CFrame.new(
      -1, 0, 0, 
      0, 0, -1,
      0, 1, 0,
      0, 0, 0
    )
    

    Where:

    • -1 0 0 : X-axis direction
    • 0 1 0 : Y-axis direction
    • 0 0 -1: Z-axis direction, reflecting a specific rotation combination.

    But exact values in the rotation part may depend on the actual rotation order and matrix calculations. The exact interpretation might vary due to the complexities of matrix multiplications involved in CFrame.

    To further understand or debug the resulting matrix, examining each step of CFrame transformation or using visual tools like a 3D visualizer within Roblox Studio can be immensely helpful.

  3. User

    how do i change the Y of the orientation?

  4. Assistant

    To change the Y-component of the orientation in a CFrame, you simply create a new CFrame with the desired rotation around the Y-axis and multiply it with the original CFrame. Here is how you can modify the Y-component of the orientation:

    1. Start with your initial CFrame, which includes both position and orientation.
    2. Create another CFrame that represents the new rotation around the Y-axis.
    3. Multiply the two CFrame objects to get the final combined CFrame.

    However, since you only want to alter the Y-component, ensure that changes to the X and Z components are not affecting your new rotation unless desired.

    Here's an example, let's say you want to change the Y-component of the orientation to 45 degrees (π/4 radians):

    local position = CFrame.new(0, 0, 0) -- Original position
    local initialOrientation = CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0)) -- Original rotation
    local initialCFrame = position * initialOrientation
    
    local newOrientationY = CFrame.Angles(0, math.rad(45), 0) -- Specify only the Y rotation you want
    local newCombinedCFrame = initialCFrame * newOrientationY -- Here's the combined CFrame
    
    print(newCombinedCFrame)
    

    In detail:

    1. initialCFrame is created by combining the initialOrientation with the position.
    2. newOrientationY is a new CFrame that specifies the new rotation around the Y-axis.
    3. newCombinedCFrame combines initialCFrame with newOrientationY, which effectively alters the Y component of the combined CFrame.

    This approach compounds the Y-rotation onto the existing orientated CFrame. If you aim to set a specific Y-rotation overriding the existing one, consider isolating only the Y rotation and recombining it:

    For a more direct approach to specifically set the orientation while disregarding the initial, recomposing the exact desired rotation:

    local position = CFrame.new(0, 0, 0)
    local newYOrientation = CFrame.Angles(math.rad(-90), math.rad(45), math.rad(0))
    local combinedCFrame = position * newYOrientation
    
    print(combinedCFrame)
    

    Here, newYOrientation directly sets all new angles (with the desired Y component).

    By these processes, you can control how the Y-axis rotation is changed and combined with the other positional and orientational components.

  5. User

    i have the position: 0, 0, 0 and the orientation: -90, -180, 0, and i want them placed inside a CFrame.New().

  6. Assistant

    If you want to encapsulate both the position (0, 0, 0) and the orientation angles (-90, -180, 0) directly into a CFrame.new, you can achieve this by combining a position CFrame with a rotational CFrame.

    However, if you wish to directly construct a CFrame with both position and orientation in one go, you can use CFrame multiplication or another convenient way in Roblox. Here’s how you can properly build a CFrame with the specified position and orientation:

    1. Create a CFrame for the position:

      local position = CFrame.new(0, 0, 0)
      
    2. Create a CFrame for the rotation angles:

      local rotation = CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0))
      
    3. Combine the position and rotation CFrame objects:

      local combinedCFrame = position * rotation
      
    4. Alternatively, directly specifying the full transformation using CFrame.new:

    Unfortunately, CFrame.new does not take rotation arguments directly in degrees without converting them into a rotational matrix, so option 3 is the proper way to go about it.

    Here is the complete example:

    -- Step 1: Create a CFrame representing the position
    local position = CFrame.new(0, 0, 0)
    
    -- Step 2: Create a CFrame representing the orientation
    local rotation = CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0))
    
    -- Step 3: Combine the position and the orientation
    local combinedCFrame = position * rotation
    
    -- Output the combined CFrame
    print(combinedCFrame)
    

    When you print combinedCFrame, it will display the resultant transformation matrix with proper orientation and position. This object can now be used to transform parts, models, or other objects within Roblox.

    The combinedCFrame encapsulates both the position (0, 0, 0) and the orientation specified by the angles (-90, -180, 0) in the form of a rotation matrix and translational vector in Roblox's coordinate space.

  7. User

    do you know what the result of the print will be?

  8. Assistant

    When you create a CFrame with a given position and orientation and then print it, the result is displayed as a matrix that encapsulates both the translation and rotation components. For the specific orientation angles you've provided, the resulting CFrame after combining them may have a somewhat complex internal representation in matrix form.

    Here's an elaboration based on your inputs:

    1. Position: (0, 0, 0)
    2. Orientation: -90° around X-axis, -180° around Y-axis, and 0° around Z-axis.

    Combining the position (0, 0, 0) and orientation angles using CFrame.Angles and then printing the CFrame yields a matrix. We'll break down the detailed computation:

    local position = CFrame.new(0, 0, 0)
    local rotation = CFrame.Angles(math.rad(-90), math.rad(-180), math.rad(0))
    local combinedCFrame = position * rotation
    
    print(combinedCFrame)
    

    Let's compute what happens step-by-step:

    1. CFrame for the rotation: CFrame.Angles computes the rotation matrix based on the input angles.

      • Rotation about the X-axis by -90°:
        • Converts to a matrix:
          | 1   0    0 |
          | 0   0    1 |
          | 0  -1    0 |
          
      • Rotation about the Y-axis by -180°:
        • Converts to a matrix:
          | -1  0   0 |
          |  0  1   0 |
          |  0  0  -1 |
          
      • Rotation about the Z-axis by 0°:
        • No change beyond identity matrix.

      Combining these rotations (Note: matrix multiplication is not commutative):

      • The combined rotation matrix from the angles -90, -180, 0 would be:
      |-1  0  0 |
      | 0  0  1 |
      | 0  1  0 |
      
    2. Position part: Since the position is (0, 0, 0), it does not affect the matrix significantly beyond the translation vector.

    When printed, the expected output will represent this transformation, potentially shown in the format CFrame.new:

    CFrame.new(
        -1, 0, 0, 
        0, 0, 1,
        0, 1, 0,
        0, 0, 0
    )
    

    However, be mindful, different matrix representations in terms of different rendering engines may affect exact interpretations and formatting) addresses the anticipated spatial transformation combining both position and orientation:

    CFrame: (Matrix4x4)
     Columns:
      [0] Vector3: (-1, 0, 0)
      [1] Vector3: (0, 0, 1)
      [2] Vector3: (0, 1, 0)
      [3] Vector3: (0, 0, 0)
    

    These encapsulate positioning at origin and specific rotations creating final CFrame. Use visualizing actual object transformations validating representation accuracy.