Before reading know that Pitch means looking up or down, Yaw means turning left or right and roll means tilting to the left side or the right side yknow
This code isn’t doing me any favours
cv.Angle = -math.acos((ray.Normal):Dot(LastINIT.CFrame.UpVector )) -- stick to rads ig
if Utility.IsTilted(cv.cart.PrimaryPart) < 0 then
cv.Angle = -cv.Angle
end
My game is called Downhill Rush.
I’m working on a stabilization system.
Apparently the game uses parts called INIT which are invisible and their LookVector is pointing directly downhill or in the direction the carts are meant to travel
The map includes bumps and curves along the road but these rotate the car along the Z axis. Very Good.
The stabilization code above works by shooting a ray down and looking for the Normal of the ray which tells us the direction of the surface.
It does a trigonometric operation to get the angle. It uses this angle to adjust the bodygyro.CFrame property to keep the car in line with the surface it is on.
Here’s the issue
When the car goes up a small hill it will roll either to the left or the right when it isn’t supposed to.
Try go on your studio and type
local a, b, c = workspace.a, workspace.b, workspace.c
local rayNormal = workspace.a.CFrame.UpVector
local MainCFrameUpVector = workspace.B.CFrame.UpVector
local origcfb = workspace.b.CFrame
Angle = -math.acos((rayNormal):Dot(MainCFrameUpVector )) -- stick to rads ig
c.CFrame = c.CFrame * CFrame.Angles(0,0,Angle)
wait(2)
b.CFrame = origcfb
Roll the part called “a” to the side and c will follow
now pitch the part a upwards and c will tilt to the side? It’s not supposed to.
A method i’ve thought of is.
Help me
Get the raynormal.
Flip it by 90 degrees forward relative to the MainCFrameUpVector (This is the stabilization CFrame which can have any direction it wants)
Create a new CFrame from this.
Get the Z or roll component of this CFrame and assign it to Angle