Using raycast normal

Because the Vector3 orientation is in something called world space, meaning it’s relative to the world and not the CFrame object.

You can think of the CFrame as a tilted Y axis due to the initial CFrame.lookAt line. We then want to apply a rotation along this axis rather than along the Y axis in world space which points upwards.

image

1 Like

oh i think i understand, how can that be solved though?

1 Like

You apply a change in rotation by using the ApplyRotation function I sent previously. Just remember that the rotation is in radians and must be converted if you input the rotation in degrees with math.rad(degrees).

2 Likes

is math.pi just the kind of default? if so how is that like editted?

1 Like

math.pi is in radians and is the same as 180 degrees. Optionally, math.rad(180).

1 Like

so how can i change that while playing

wait so this has to completely bypass any sort of orientation? would look vector work?

is lookvector the right idea? how can the -1 to 1 of a lookvector be turned into a value the math can understand

For that you could use CFrame.fromAxisAngle. Note the rotation is also in radians.

local cframe = CFrame.new(rayresult.Position) * CFrame.fromAxisAngle(rayresult.Normal, math.rad( ? ))

The previous code was built upon you insisting on getting an orientation from it, otherwise I’d go with this.

what is the question mark for?

Input. Just for you to know that it’s variable.

i dont know what to set as the input

is the input an angle? then why does it need the other stuff??? im so confused

What besides the rotation are you referring to?

local cframe = CFrame.new(raypos) * CFrame.fromAxisAngle(raynormal, math.rad( ? )) -- is this supposed to be like math.pi or something?
local cframe = CFrame.lookAt(raypos, raypos + raynormal) -- if i use one i dont need the other?
cframe *= CFrame.fromOrientation(0, math.pi,0)
local radx, rady, radz = cframe:ToOrientation()

how can i get an angle if the orientation value isnt right?

Line 2 to 4 was to convert a CFrame into an orientation after a rotation offset is applied like you asked for. Line 1 replaces line 2 and 3.

ok so if i want to keep the orientation thing wait so if a radian is 180 degrees, is lookvector also radian? if so can i do

local cframe = CFrame.lookAt(raypos, raypos + raynormal)
	cframe *= CFrame.fromOrientation(0, lookVector.Z*180,0)

Just because they’re both vectors, doesn’t mean that their values mean the same. The rotation is represented in something called Euler angles, while the lookVector is a directional unit vector (has a magnitude of 1) pointing in the direction that the CFrame is facing. There’s a significant difference, don’t mix them.

so how am i supposed to get the correct value to the way the player is facing?