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
 

Re: How to get Y angle axis of CFrame.new(pos, point)

Previous Thread :: Next Thread 
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 01:09 PM
-- simplified --
local NewFrame = CFrame.new(Vector3.new(0, 10, 0), Mouse.Hit.p)
Part.CFrame = NewFrame

This works fine, but what if I want it only on the Y axis?


local NewFrame = CFrame.new(Vector3.new(0, 10, 0), Mouse.Hit.p)
local _, RotY, _= NewFrame:toEulerAnglesXYZ()
Part.CFrame = Vector3.new(0, 10, 0) * CFrame.Angles(0, RotY, 0)

This actually doesn't work. Probably because toEulerAnglesXYZ doesn't get the full matrix or something.

Can anybody help me apply this only to the Y rotation axis?
Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 01:11 PM
Part.CFrame = CFrame.new(0, 10, 0) * CFrame.Angles(0, RotY, 0)

Sorry, i simplified this for the forum. There's nothing wrong with the script itself.
Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 01:21 PM
Actually vertical rotation comes from the first argument, not the second (rotation is not the same as positioning). I believe this is what you want:

local OrigVec = Vector3.new(0, 10, 0)

local Rot1,_,_ = CFrame.new(OrigVec, Mouse.Hit.p):toEulerAnglesXYZ()

Part.CFrame = CFrame.new(OrigVec) * CFrame.Angles(Rot1, 0, 0)


Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 01:26 PM
http://wiki.roblox.com/index.php?title=File:AngularvelocitydiagramV2.png

I want the 2nd one in the diagram (0,1,0)
Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 01:26 PM
Well, that's one direction of vertical rotation, if you wanted the other direction then it would be:

local OrigVec = Vector3.new(0, 10, 0)

local _,_,Rot1 = CFrame.new(OrigVec, Mouse.Hit.p):toEulerAnglesXYZ()

Part.CFrame = CFrame.new(OrigVec) * CFrame.Angles(0, 0, Rot1)

Ultimately it depends which surface you want being rotated.

Think of it like this:

CFrame.Angles(Rot1, Rot2, Rot3)

Rot1 = Vertical rotation of the FrontSurface and BackSurface
Rot2 = Horizontal rotation (spinning)
Rot3 = Vertical rotation of the LeftSurface and RightSurface


Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 01:27 PM
Oh, I presumed you meant make it point vertically. Then yeah, just do:

local OrigVec = Vector3.new(0, 10, 0)

local _,Rot1,_ = CFrame.new(OrigVec, Mouse.Hit.p):toEulerAnglesXYZ()

Part.CFrame = CFrame.new(OrigVec) * CFrame.Angles(0, Rot1, 0)


Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 01:31 PM
I want the Y axis and the Y axis only. The problem is that it doesn't fully apply that in:

local NewFrame = CFrame.new(Vector3.new(0, 10, 0), Mouse.Hit.p)
local _, RotY, _= NewFrame:toEulerAnglesXYZ()
Part.CFrame = CFrame.new(0, 10, 0) * CFrame.Angles(0, RotY, 0)

So that it only spins to where my mouse is. The problem is it only works on like half the rotation(no clue why)
Once it gets to the other half, it applies the inverse of my mouse, so if i was going clockwise around the part, it would move counterclockwise
Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 01:48 PM
b
Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:01 PM
Are you sure you aren't trying this in studio where your mouse is pointing to the sky (this would cause that motion because you are pointing to an empty space which has distance so even though you're pointing to one area of the screen it would interpret it as another). Make sure that your mouse is pointing to a part when you're testing it. Also, this would work too:

Part.CFrame = CFrame.new(Part.CFrame.p, Vector3.new(Mouse.Hit.X, Part.CFrame.Y, Mouse.Hit.Z))


Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
10 Feb 2016 02:01 PM
please don't use :toEulerAnglesXYZ()

if you want to do what Vaeb is saying, do this:

```lua
local angleCF = fullCF - fullCF.p

-- use angleCF elsewhere in your code
```

and if you want to get the angle from an axis:

```lua
local look = fullCF.lookVector
local angleFromUp = math.acos(look:Dot(Vector3.new(0,1,0)))

print("Y angle:", math.deg(angleFromUp)
```

-Push poorly written test can down the road another ten years
Report Abuse
rvox is not online. rvox
Joined: 18 Feb 2011
Total Posts: 5380
10 Feb 2016 02:06 PM
please don't use :toEulerAnglesXYZ()[2]
Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 02:08 PM
I was thinking about using my own trigonometry, but I tried what you did and it didn't work.

And I'm testing this in a SB and studio, although it doesn't matter.
Report Abuse
rvox is not online. rvox
Joined: 18 Feb 2011
Total Posts: 5380
10 Feb 2016 02:10 PM
This might be what you want

local p = Vector3.new(0,10,0)

Part.CFrame = CFrame.new(p,Vector3.new(p.x,Mouse.Hit.Y,p.z))
Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:12 PM
@Maker I just tested my solution in studio (with a part underneath) and it worked perfectly fine.

@Digpoe I'm afraid you're wrong, that would get the total rotation, he just wants it to spin horizontally.


Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:13 PM
Also yeah CFrame-CFrame.p would be better but it doesn't matter too much in case like this where best guess angles are fine. Also, my altered method doesn't even involve covnerting to angles.


Report Abuse
rvox is not online. rvox
Joined: 18 Feb 2011
Total Posts: 5380
10 Feb 2016 02:14 PM
Nevertheless, euler angles should be avoided in general, due to the problem of gimbal lock

Working with the matrix or other forms of rotation representation is better
Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:16 PM
Yeah I agree rvox, refer again to my previous post.


Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:17 PM
Also I was working from Maker's example rather than writing it from scratch.


Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 02:17 PM
I was talking about digpoe.

But it shouldn't matter if I run in studio or not lol.
Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:19 PM
Ah ok. Also I simply meant because if you run in studio without a part underneath you will be pointing at sky, in which case it does matter (mouse positioning messes up past a certain angle when pointing at sky)


Report Abuse
Vaeb is not online. Vaeb
Joined: 20 Jul 2014
Total Posts: 25
10 Feb 2016 02:28 PM
tl;dr

My original method: Don't use, 'tis not very efficient.
My revised method (the one with no angles): Will work fine
digpoe's method: Wrong he got the full angle
rvox's method: No clue what he's trying to achieve there, definitely wrong

(In a skype call with Maker atm and he seems to have got it working now)


Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
10 Feb 2016 02:30 PM
Vaeb's method works :D

local Pos = CFrame.new(0, 10, 0).p
local NewFrame = CFrame.new(Pos, Vector3.new(Mouse.Hit.X, Pos.Y, Mouse.Hit.Z))
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