Yes the part would be on the surface and yeah finding the surface direction is the easy part
Why dont you just use the surface normal of where the ray hits and if it hits the part do stuff
I dont think you need to convert anything, unless im missunderstood you
Oh are you sure Cause yesterday I did that and it tilted slightly where I wanted it to go
Unless I did something wrong
Maybe you did it right but you didnt rotate it enough?
Im no expert at math and havent really had any experience using surface normals of rays
This would be for random amounts of surface direction(normals) using a ray(Mouse position)
I believe you do have to convert something but I don’t know the math
Im sorry but Im not that good at math; I tried to help you as much as I could
I know you can figure it out
Good luck!
Thank you anyways! I find the solution sooner or later
Does this work?
local normal = -- the normal vector
local currentUpVec = part.CFrame.UpVector
local angle = math.acos(currentUpVec:Dot(normal)
local axis = currentUpVec:Cross(normal)
part.CFrame = CFrame.fromAxisAngle(axis, angle)*part.CFrame
I would have to try this once I get home thanks for the reply hopefully this works!
I don’t understand some lines of your code you typed in(“Cross”,acos",“Dot”,“FromAxisAngle”) can you send me a video on where I can fully learn this line of code or tell me what I should be researching or if you can explain it yourself I would appreciate it
i think i know what you mean. you just find the delta difference of them and set it.
make sure to set that cframe to the pivot if the object u rotating is rigged
The cross product of two vectors gives a vector that is perpendicular to the two vectors. The dot product of two unit vectors is a number that tells how close the directions are to each other. The arccosine of the dot product gives the angle between the vectors, because the dot product is the cosine of that angle.
CFrame.fromAxisAngle takes an axis to rotate around, and an angle that tells how much to rotate around that axis.
I don’t know how these things are calculated.
by perpendicular you mean a vector3 between two other vector3 right?
and Im guessing fromaxisangle basically applys its own orientation as a 0,0,0
I believe RoBoPoJu is offline if anyone can tell me how they learned cross product or dot product that will be cool cause I’m completely confused I been researching about trigonometry and quaternions for the past 2 days for all of my periods including lunch in school and as well at home can’t seem to figure this out I am a very visual learner but words will do fine as well
I want to note I barely found out last week what .unit is and how it works
When lines are perpendicular, there’s a 90 degree angle between them. For example, the global y axis in roblox is perpendicular to the global x and z axes. There’s a 90 degree angle between y and z axes and between y and x axes. There’s also a 90 degree angle between x and z axes, so each of these axes is perpendicular to the other two.
There are always two possible cross products for two vectors. The directions of these two are opposite and which one you get depends on which order you put the vectors in the calculation.
Vectors have a length, but the global axes are infinite to both directions. However, the positive direction of the y axis could be described with vector (0, 1, 0) and the positive direction of x axis with vector (1, 0, 0). The cross product of these would be the positive direction of z axis, which is (0, 0, 1) or its negative direction, which is (0, 0, -1). The cross product isn’t always a unit vector (vector with length 1), but you can get its unit vector by didving the vector with its length. In roblox, the unit vector of a vector is the value of its unit property.
Here is an example of using a raycast to orient a part according to the surface normal using the advanced CFrame trick to rotate from the parts current UpVector to the floors normal vector.
Thanks for this explanation it helps of understanding it but just can’t seem how to use the cross product
am I suppose to use it like this
game.Workspace.Part.Position:Cross(Variable1)
What am I suppose to put on variable1? direction, orientation,position of one of the surfaces? I believe its direction
and whatever it is it returns an orientation I’m guessing
Reading this post helped me a bit but why did you use a dot product? isn’t that to return a individual unit vector saying where is the position of part1 from part0 from like in a orientation perspective I believe
–note using part1 and part0 as a example
Hi do you still have that game so I can experiment with it it will really help me
The script should still be in that post I linked. just copy and paste it into an anchored part and then run it and see how it goes.
Any part will do but I chose a wedge since you can see where it’s pointing kinda.