English 中文(简体)
How do I CFrame parts?
原标题:

I ve heard that you can tilt a part by a precise amount using the .CFrame property. However, I m unclear on how to use it. The following code does not work:

Workspace.Part.CFrame = CFrame.new(90,0,45)

It is not rotating the part by 90 degrees and 45 degrees. What am I doing wrong?

问题回答

First, use the CFrame.fromEulerAnglesXYZ function to create a new CFrame pointing in the direction you wish. Then, use Vector3 math to move the CFrame into the desired position. EG.

local cframe = CFrame.fromEulerAnglesXYZ(XRADIANS, YRADIANS, ZRADIANS)
cframe = (cframe - cframe.p) + Vector3.new(XPOS,YPOS,ZPOS)

The documentation states that a Coordinate Frame (CFrame) constructor that takes 3 parameters is defining a position offset. Therefore, your example code would move the part 90 along the x-axis and 45 along the z-axis. To perform a rotation as you attempted see the CFrame.fromEulerAnglesXYZ function.

The arguments taken specify position, not rotation

I had this trouble too when I was starting to CFrame. They are RADIANS, not DEGREES. I have written a quick CFraming guide on ROBLOX, here.

If you re struggling with radians, you should look at the ROBLOX wiki page on radians to gain a basic understanding: wiki.roblox.com/index.php/Radians

Thanks!

-pighead10

-- Rotates the part by 90 degrees. If you want to change the axis your
-- rotating it on Use a different placement such as CFrame.Angles(math.rad(90),0,0)
Workspace.Part.CFrame = Workspace.Part.CFrame * CFrame.Angles(0, math.rad(90), 0)




相关问题
Wrapping a Lua object for use in C++ with SWIG

Currently I know how to have C++ objects instantiated and passed around in Lua using SWIG bindings, what I need is the reverse. I am using Lua & C++ & SWIG. I have interfaces in C++ and ...

Can t lua_resume after async_wait?

I have some lua script that have some long running task like getting a web page so I make it yield then the C code handle get page job async, so the thread free to do other job and after a specify ...

How to remove a lua table entry by its key?

I have a lua table that I use as a hashmap, ie with string keys : local map = { foo = 1, bar = 2 } I would like to "pop" an element of this table identified by its key. There is a table.remove() ...

Lua plain string.gsub

I ve hit s small block with string parsing. I have a string like: footage/down/temp/cars_[100]_upper/cars_[100]_upper.exr and I m having difficulty using gsub to delete a portion of the string. ...

why do i get "attempt to call global require (a nil value)"?

I have 3 lua files, Init.lua, FreeCamera.lua and Camera.lua , init.lua calls require "Core.Camera.FreeCamera" Free Camera: module(...) require "Core.Camera.Camera" local M = {} FreeCamera = M M ...

热门标签