Question on rotating

Hello, I have currently experimented CF.Rotate() method provided on Unity engine, which is able to rotate an object from a direction as shown in the following image :

I want basically to transcribe the behavior of that method on Roblox using a directional vector + an input, for example :

Part.Rotate( Part.CFrame.RightVector, 40° )

How am I able to achieve that result in Roblox ? I’ve recently got introduced to CFrames, and haven’t read the whole documentation about it… :confused:

Do you want it to smoothly rotate?

Cause if so, use tween service to achieve this.

Simply change the orientation of the BasePart to rotate it, its one of its properties :slight_smile:

So by doing BasePart.Orientation you get the current orientation, then you can simply do BasePart.Orientation = BasePart.Orientation + 40 to rotate it by 40 degrees.

The goal of this is way more complex, I’m not searching to lerp it or rotating it smoothly, I want to rotate it relative to the given direction…

My apologies, you can do this through doing :ToWorldSpace() so its relative to itself, you can read more in this article:
https://developer.roblox.com/en-us/articles/Understanding-CFrame

Which has relative rotation.

I mean, that’s not really what I need… I’ve said I want to get the behavior of that method on Roblox…

i think you are looking for the CFrame.fromAxisAngle(dir, rotation) constructor:

local dir = Part.CFrame.RightVector
local Angle = math.rad(40)

local Rotation = CFrame.fromAxisAngle(dir, Angle)
local CF = Rotation + Part.Position
1 Like

Ah, right. This is my field of ‘expertise’ right here.

I would definitely go for, and use the method CFrame.fromOrientation(rX, rY, rZ) to apply orientation to a BasePart.

Where rX is up/down, rY is left/right and rZ is tilt left/right. Oh, and remember, these rotations are in radians. To convert degrees to radians, simply use math.rad(deg) or math.deg(rad) for radians to degrees. Also, remember that the symbol * is basically the same as addition +, just for CFrames.

You can…

a) Apply orientation to an existing CFrame.

Example
BasePart.CFrame = BasePart.CFrame * CFrame.fromOrientation(math.rad(30), 0, 0)

Or…

b) Construct a new CFrame with the desired orientation that you want.

Example
BasePart.CFrame = CFrame.new(0, 5, 0) * CFrame.fromOrientation(math.rad(30), math.rad(90), 0)

Useful resources:

Try this out, and don’t forget to play around!

1 Like

Well, I’m slightly confused then because from the example you provided of what you want :ToWorldSpace(), which is how you rotate something relative to its current orientation a specified amount, whereas running multiplication as you normally would is relative to the world itself?

Seeming as we use x y z, by changing the x y z values you’d be rotating around the specified axis. And so if you only want to rotate around a singular axis you’d do Cframe.Angles(0,0,math.rad(7)) for the z component only.

I dont know what CF.Rotate does in Unity, but in roblox we rotate parts with using CFrame.Angles(), so we can rotate a part like this:

Part.CFrame = Part.CFrame * CFrame.Angles(math.rad(30), 0, 0)
1 Like

Haha, I used to bring a lot the function fromOrientation() to solve my problems, but in that case it would in no way fix the problem. I given a method that rotates FROM a directional vector, a total different case.

Which concerns your answer format, I really like it and it’s very intuitive ! Keep it up.

If it didn’t answer what you were asking about, what are you really asking about then?

1 Like

It appears to be what I was searching for, thanks ! As I said I haven’t experienced every methods that Roblox provides.

To explain more what the method does, as I’m very bad at explanations I’ll provide a video of those explained at the precise timecode…

I’m not particularly sure how you can rotate a part 40 degrees in the “RightVector” as you showed because thats not how angles work.

What I have been trying to say is that by doing :ToWorldSpace() with an angle in the brackets you rotate it relative to the parts current orientation, with the rX, rY and rZ being the different ways you can orientate a part…

By looking at your video, if you want to do it relative to the world space then it would simply be:

Part.CFrame = Part.CFrame * CFrame.Angles(math.rad(40), 0, 0) -- this would be 40 degrees in the x axis relative to the world.

With the parameters being:
CFrame.Angles(rX, rY, rZ) where:

  • rX is the x axis,
  • rY is the y axis,
  • rZ is the z axis.

Uhm… no. On the contrary actually. This would be relative to the current CFrame.

I don’t really how to explain that, I’ve tried to give the more informations through my links and images…

I have found on the documentation related to that method these arguments :

And here, once again the source

Drawing is some times the best way to illustrate what you mean.

1 Like