guges
|
  |
| Joined: 07 May 2016 |
| Total Posts: 1515 |
|
|
| 08 Aug 2016 07:02 AM |
How can I make a CFrames up vector (cframe:vectorToWorldSpace(0,1,0)) align with the world y axis?
I'm sorry if this is a poorly phrased or ignorant question but I want to "flatten" a CFrame so theres no vertical rotation |
|
|
| Report Abuse |
|
|
| 08 Aug 2016 08:05 AM |
I'm not sure _exactly_ the best way to do it, but this should work:
local function Flatten(CF) local X, Y, Z, XX, YX, ZX, XY, YY, ZY, XZ, YZ, ZZ = CF:components() return CFrame.new(X, Y, Z, XX, 0, ZX, 0, YY, 0, XZ, 0, ZZ) end
Hopefully that works. If it doesn't, you can try this, but I'm not sure if it will give different results, I'm not sure if CFrames require unit vectors to work properly.
local function Flatten(CF) local X, Y, Z, XX, YX, ZX, XY, YY, ZY, XZ, YZ, ZZ = CF:components() local VecX, VecY, VecZ = Vector3.new(XX, 0, XZ).Unit, Vector3.new(0, YY, 0).Unit, Vector3.new(ZX, 0, ZZ).Unit return CFrame.new(X, Y, Z, VecX.X, 0, VecZ.X, 0, VecY.Y, 0, VecX.Z, 0, VecZ.Z) end
I may have made mistakes too, but I'm crossing my noses.
|
|
|
| Report Abuse |
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 08 Aug 2016 09:39 AM |
local function pointYDirection(position, lookAt) local lookAt = (position - lookAt).unit local arbVec = Vector3.new(0,0,1) local perp = lookAt:Cross(arbVec) local XAxis = perp:Cross(lookAt) local ZAxis = lookAt:Cross(XAxis) return CFrame.new(position.x, position.y, position.z, XAxis.X, lookAt.X, ZAxis.X, XAxis.Y, lookAt.Y, ZAxis.Y, XAxis.Z, lookAt.Z, ZAxis.Z) end |
|
|
| Report Abuse |
|
|
| 08 Aug 2016 09:42 AM |
Apparently my first function worked, better than I thought it would too.
What does yours do, Nox? I don't completely understand it, not knowing a thing about cross products. Is it just to make it look in a direction, sort of like CFrame.new(Pos, Pos+Dir)?
|
|
|
| Report Abuse |
|
|
| 08 Aug 2016 09:43 AM |
| If you want something to have no vertical rotation then you pull out the vertical toWorldSpace and inverse it to cancel out the Y angle |
|
|
| Report Abuse |
|
guges
|
  |
| Joined: 07 May 2016 |
| Total Posts: 1515 |
|
|
| 09 Aug 2016 06:16 AM |
| Two very interesting responses. I solved the problem through adjacent means but these are very interesting functions that prompt me to learn more about composing rotation matrices. Thank you both for the answers! |
|
|
| Report Abuse |
|