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

Whats wrong with my rotation?

Asked by
neoG457 315 Moderation Voter
9 years ago
c.CFrame = Player.Character.Torso.CFrame.new(0, -2, 0)*CFrame.new(0, -math.pi/4, 0)

The code should rotate 1/4 of a turn but it doesnt.

0
You're welcome EzraNehemiah_TF2 3552 — 9y

3 answers

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
9 years ago

It's very difficult to identity what transformation you are trying to apply, neoG457, but my guess is that you want to take the CFrame of the character's Torso, translate it by (0, -2, 0) and rotate by 90 degrees around the y-axis.

To translate a CFrame by a vector value you can either add or subtract a Vector3 value or multiply by another CFrame.

For example, if I want to move a CFrame called 'aCFrame' by (0,-2,0) I could either do:

aCFrame = aCFrame * CFrame.new(0,-2,0)

or:

aCFrame = aCFrame + Vector3.new(0,-2,0)

or:

aCFrame = aCFrame - Vector3.new(0,2,0)

To rotate a CFrame, we specify an angle to rotate by for each of the three axes: x (pitch), y (yaw), z (roll). Angles are specified in radians, where pi radians is equal to 90 degrees. You can either give your rotation as a multiple of pi (Today is pi day, by the way), or you can use the math.rad function to change degrees into radians.

So, if you want to rotate around the y-axis (yaw) by 90 degrees, you could either:

aCFrame = aCFrame * CFrame.Angles(0, math.pi/2, 0)

or:

aCFrame = aCFrame * CFrame.Angles(0, math.rad(90), 0)

You can compute a CFrame that is a translated, rotated version of a character's Torso by combining the above:

c.CFrame = Player.Character.Torso.CFrame * CFrame.new(0, -2, 0) * CFrame.Angles(0, math.pi/2, 0)

You can read more about CFrame on the Official ROBLOX Wiki.

0
Oops, dang, people go so hard on me when I make a slight mistake :C EzraNehemiah_TF2 3552 — 9y
0
Today is the ultimate pi day. 3/14/15. 3.1415 EzraNehemiah_TF2 3552 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

Instead of using:

c.CFrame = Player.Character.Torso.CFrame.new(0, -2, 0)*CFrame.new(0, -math.pi/4, 0)--Notice the 2nd CFrame.new

You can change the CFrames Angles. You must use math.rad on this (math.radians), in order to change the rotation of the object.

c.CFrame = CFrame.new(0, -2, 0)*CFrame.Angles(0, math.rad(-math.pi/4), 0)


You can also do this with cameras.


This was really simple. Hope this helps!

0
So, If I used the CFrame for Camera it would be "camera.CFrame" or "camera.CoordinateFrame"? woodengop 1134 — 9y
0
Thanks. neoG457 315 — 9y
0
'rad' is an abbreviation for 'radians', not 'radius'. duckwit 1404 — 9y
0
Why did someone thumbs down my correct answer? EzraNehemiah_TF2 3552 — 9y
0
Your answer is not correct, and I don't know why it has been approved as the right answer. The code that you posted is semantically erroneous; you can't call "new" on an existing CFrame value. duckwit 1404 — 9y
Log in to vote
-3
Answered by 9 years ago

Using

c.CFrame = Player.Character.Torso.CFrame.new

is incorrect because you can't create a new CFrame when one is already present. Try using

c.CFrame = CFrame.new(0, -2, 0) -- Change the position you want to teleport the player to
*CFrame.new(0, -math.pi/4, 0)
0
I think he wanted the Torso to rotate, not Teleport. woodengop 1134 — 9y

Answer this question