Is there a way to rotate a vector like this?

Im trying to rotate this offset vector (raycast.Normal) depending on the parts (raycast.Instance) rotation

NormalOffset = Vector3.new(1,0,0)

and if i had like a orientation of 90 degrees
it would be something like

RotatedVector = Vector3.new(0,0,1)

Is there a way to do this / is this possible?

could still use some help on this :pray:

Are you saying you want to rotate a vector along it’s y-axis?

Or that you want to rotate a vector based on the rotation of a part?


You probably could use the part’s CFrame to do what you want, if I am understanding the question.
So, using the example code you gave, you could try this:

local RotatedVector = raycast.Instance.CFrame.Rotation * NormalOffset

If that doesn’t give you result you are expecting, you can also try:

local RotatedVector = raycast.Instance.CFrame.Rotation:Inverse() * NormalOffset


But in the event that I misunderstood what you were asking about, you may need somthing slightly different.
Because part of me thinks what you are doing is using raycasts to align an object to the surface of another object. But you also want to be able to specify the rotation of that object around the raycast normal, as an axis.

So to visualise what I just said, it’s like a cube spinning on a table. The axis of rotation of the cube is based on the normal of the surface (the arrow pointing away from the surface).

This is what im trying to accomplish,
I used your code that you stated and it seemingly worked on only 2 axis-s as intended
image
works here
image
and here
image
then here it just kinda goes into the stud, not exactly sure how to fix this, Using :Inverse()just had the same results but switched to the z axis instead of the x

Heres the code i used

local RotSize = rayc.Instance.CFrame.Rotation * (ClientPart.Size/2)
local Offset = RotSize * rayc.Normal
		
NewCF += Offset

(Edit)
Above was tested on parts with a 90 rotation
Parts with a 180 rotation have both offsets go into the part
and -90 seems just to be the inverse of the 90 rotation

I believe i found a blanket like fix for this (its worked for me but may break in certain circumstances, not sure though)

local Dc = (V1.Normal * (RotAmount * ClientPart.Size) * .5)
local Hc = (V1.Normal * ClientPart.Size * .5)
		
local Thingy = Vector3.new(
	if (Dc.X < 0) == (Hc.X < 0) then Dc.X else (Dc.X * -1),
	if (Dc.Y < 0) == (Hc.Y < 0) then Dc.Y else (Dc.Y * -1),
	if (Dc.Z < 0) == (Hc.Z < 0) then Dc.Z else (Dc.Z * -1)
)
1 Like

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