How can I "rotate" a Vector3?

How can I “rotate” a Vector3, for example I have a Vector3 (1, 0, 2) and rotate 90 degrees to get something like (2, 0, -1)?

If you’re trying to rotate a vector or vector3 (not of a basepart) you can’t but you can do it with baseparts (basepart vector).

local Part = script.Parent

Part.Rotation = Vector3.new(0,90,0) -- It is already in degrees.

Assuming you have Vector3(1,0,2):

local Part = script.Parent

Part.Rotation = Vector3.new(0,0,0) + Vector3.new(0,90,0) -- It is already degrees
2 Likes

How do I use the function? What are v, axis, and amount?

Use sin and cos

depending on what axis you want to rotate it you need to slightly change the formula

around the Z axis:
x = x * cos(angle) - y * sin(angle)
y = x * sin(angle) + y * cos(angle)
z = z

around Y axis:
x = x * cos(angle) - z * sin(angle)
y = y
z = x * sin(angle) + z * cos(angle)

around X axis:
x = x
y = -y * cos(angle) + z * sin(angle)
z = y * sin(angle) + z * cos(angle)

8 Likes

Out of curiosity why do you need to rotate the Vector3? There might be some functions roblox already has that might be able to either simplify or solve the problem.

I want a script to manipulate structures (Like create or move them) and work in any direction.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.