generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Align CFrame with world space axis'

Previous Thread :: Next Thread 
guges is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image