pug6_4
(pug)
April 16, 2022, 2:44pm
#1
So, i have this normal angle
local NormalAngle = math.acos(Normal:Dot(Hoverboard.PrimaryPart.CFrame.UpVector)) * 3
And it does quite work untill you go reverse, and that’s because i’m adding it onto the X axis like this
CFrame.Angles(NormalAngle,math.rad(90),0)
So, does anyone know how i could make it relative to the board?
The raycast is firing downwards from the hoverboard btw.
Does anyone know how i could make the normal relative to the board too?
You mean orient to surface normal? Quaternions are your best bet, though really it’s just 3d rotation from one vector to another vector.
Rather than trying to convert this up vector into an angle which is also complicated it’s better to leave it I would rather use @EgoMoose advanced CFrame technique to leave it in terms of vectors.
We can obtain a CFrame rotation to align the current persons “UpVector” to the new surface upvector. Here is an example script and video.
The advantage of this method is that it will allow you to rotate along the new upVector without having to specify a right vector as a CFrame.fromMatrix solution.
…
pug6_4
(pug)
April 16, 2022, 3:01pm
#3
Ok well, would this work with me adding the normal angle onto the hoverboard? as that’s mainly what i’m doing.
Hoverboard.PrimaryPart.BodyGyro.CFrame = LastUpdatedAngle * CFrame.Angles(0,math.rad(90),0) + getRotationBetween(Hoverboard.PrimaryPart.CFrame.UpVector,Normal,Vector3.new(1,0,0)).Rotation
Soliform
(Soliform)
April 16, 2022, 6:48pm
#4
Simply construct a rotation matrix out of the surface normal as an upVector:
local up = surfaceNormal -- fill this in
local fwd = -Hoverboard.PrimaryPart.CFrame.LookVector * Vector3.new(1, 0, 1)
local right = up:Cross(fwd)
Hoverboard.PrimaryPart.CFrame = CFrame.fromMatrix(Hoverboard.PrimaryPart.CFrame.Position, right, up, fwd)