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

CFrame giving the wrong angles?

Asked by
RoboFrog 400 Moderation Voter
10 years ago

This has been frustrating me for the past 3 - 4 hours, and I'm quite fed up of debugging on my own. I'm trying to move a block out by a certain amount of studs for 16 times, while keeping it at a -89.98 degree angle. Here's the main portion of the script:

local parx1 = script.Parent.CFrame.X
local pary1 = script.Parent.CFrame.Y
local parz1 = script.Parent.CFrame.Z
local parch  = parx1

game.Workspace.bookcheck.Touched:connect(function(hit)
    for i = 1,16 do
        parch = parch + .05
        script.Parent.CFrame = CFrame.new(parch, pary1, parz1) * CFrame.Angles(0, -89.98, 0)
        wait(.05)   
    end
end)

In this, "bookcheck" is an invisible block with collisions off that fills an entire room. This script is within another block, and triggers whenever the other block is touched, of course.

The block moves correctly when triggered, however, the rotation is always messed up. No matter what I change the "90" to gives me the same rotation whenever it moves. The regular rotation is "0, -89.98, 0", but whenever I modify the Y axis (which seems to act like the X axis in-game), it suddenly makes the rotation "-180, 63.38, -180"

I would just use straight Vector3 (which doesn't mess up the rotation), but it's collision detection when moving makes it unable to be used.

Any help on this extremely frustrating issue would be greatly appreciated, since I'm am completely out of ideas, even after scouring every method the wiki has to offer.

0
CFrame.Angles takes radians, not degrees, so you need to do math.rad(-90) instead. Yes, I just rounded it to 90 degrees. Tkdriverx 514 — 10y
1
That worked perfectly! It'll help me a ton for many other things, since I've not realized how to accomplish angle fixes until now. Feel free to post that as an answer, and I'll accept it. RoboFrog 400 — 10y

1 answer

Log in to vote
2
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

CFrame.Angles uses Radians, not Degrees, so to accomplish this, you need to do CFrame.Angles(0, math.rad(-90), 0).

Wiki page

Ad

Answer this question