Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use CFrame.fromAxisAngle?

Asked by 5 years ago
Edited 5 years ago

I was exploring the CFrame methods on the wiki page, then I came across CFrame.fromAxisAngle. I tried searching up some tutorials or videos, but none of them gave me information how to use it.

According to the wiki, I need a unit vector and a rotation in radians. I get the rotation parameter, but not the unit vector one. Can someone please tell me how to use it. Here's what I'm trying to do:

-- This is not the full code. Only the part where I need help
local gunAngle = CFrame.fromAxisAngle(Help here, math.rad(49))
gun:SetPrimaryPartCFrame(CFrame.new(gunCFrame, gunLookAt)*gunSway*gunAngle)

Edit: I forgot to tell you that I'm using CFrame.fromAxisAngle to prevent gimbal lock.

0
Uhh... anyone? User#25270 0 — 5y

1 answer

Log in to vote
1
Answered by
EgoMoose 802 Moderation Voter
5 years ago
Edited 5 years ago

This is actually more of a math question than anything. To answer it I recommend you read this

In summary:

Typically in rotations we use pitch, yaw, and roll. We tend to think of any end goal rotation as some ordered combination of these three axes. This is what the constructors CFrame.Angles, CFrame.fromEulerAnglesXYZ, CFrame.fromEulerAnglesYXZ, and CFrame.fromOrientation do. For example, I may represent an end rotation as 45 degrees pitch, then 90 degrees yaw, and 0 degrees roll.

You might argue this is kind of a silly way to represent rotation b/c it's a very indirect way of reaching an end rotation and as a result isn't very intuitive. CFrame.fromAxisAngle is a potential solution to this. Instead of using three fixed axes that are independent of each other why not use one axis that would allow us to make the direct rotation.

It can be a very difficult to visualize without any images, but hopefully the article above will provide that for you.

0
rip egomoose, OP deleted their account User#24403 69 — 5y
Ad

Answer this question