So I am working on a slide mechanic for my game and i want to be able to calculate the slope vector from just the normal vector. I have already achieved the slope vector of wedges because I can just do the arc tangent and then some CFrame manipulation for the look vector of it. The CFrame part is inefficient I know, but here is the wedge slope code.
local slopeAngle = math.atan(wdge.Size.Y/wdge.Size.Z)
local cf = CFrame.Angles(-slopeAngle,0,0)
cf = hit.Instance.CFrame:ToWorldSpace(cf)
print(cf.LookVector) -- the slope vector
Now you may be asking, why would you need the slope vector of things other than a wedge, which I agree with if I wasn’t using spheres, or meshes, or rotated parts.
Could any vector math magicians help me with this problem?
I’ve done this before. All I really did was use a cframe. When raycasting, I got the surface normal and then created a cframe from the hit position looking in the direction of the normal. Then I just used the
UpVector. If I remember correctly, there’s another way using the dot product, but I’ve forgotten it. I can look through my projects tomorrow if you want a relevant code sample.
I would appreciate that, and if you have the dot product usage I would prefer it as it would be presumably more efficient
I found the solution! The earlier comment by @BuilderBob25620 led me on the right track till I found the most effecient way, that just uses some of the underlying math of the lookAt functions.
local upVector = Vector3.new(0, 1, 0)
-- You have to remember the right hand rule or google search to get this right
local rightVector = normal:Cross(upVector)
local slopeVector = rightVector:Cross(normal)
Hope this helps anyone else who needs it!
I’m so confused ik you found out how to do
It but idek how to start from scratch