its been a year and ive gotten much better at physics based math. i know the way to solve this so for anyone who is looking for a solution, i will post it now
i wont be posting any code, just the math you will need to solve it
the ultimate problem is that the car is not staying where it should on the planet
when on flat gound every force is normal, as you can see in this picture
you can see that the gravity force and normal force are straight up and down, so the car wont be push to the side
now lets see the forces when on a sphere
we now have a force pushing to the left Fgx
and up Fgy
, or in this case up the arc of the circle
the gravity force always points directly to the center of the circle, since thats where gravity is coming from, and the normal force is always perpendicular to the surface
how would we solve this? lets look at a close up
so in this case, the gravity force is pushing down the slope. you can get the x and y components of the gravity force (relative to the slope) by using Fg * sinθ
and Fg * cosθ
, sin is the x component and cos is the y component. for those who don’t know trig, θ
is an angle, usually in radians, which is what the math.cos
and math.sin
equations take so make sure your angle is in radians before putting it in by using math.rad
(if you call this on an angle already that’s in radians it will mess it up too)
so we have the vertical already delt with, this is our normal force. the minimal amount of force required to keep the car from pushing into the ground, it will still touch the ground but our spring force will be the one pushing it off the ground. our normal force would just be the y component of the gravity force, Fg * cosθ
since its whats pushing into the ground so we need to counter that
but now we got a big issue, we have the gravity force pushing us down the slope Fg * sinθ
we can introduce a new force to push in the opposite way to counter that, we will call this the friction force (f
)
lets look at our new forces
to keep something from moving we need the net force (add up all the forces and see what you get) to be 0, so lets look at the vertical with respect to the slope
we have Fn
pushing up, which this is equal to Fg * cosθ
going down so the vertical does cancel out, Fnety = 0
how about the horizontal? we have f
pushing up the slope and this is equal to Fg * sinθ
pushing down the slope. they cancel out so Fnetx = 0
if Fnetx = 0
and Fnety = 0
we can say that Fnet = 0
if the net force is 0 then we won’t be moving. we have solved it!
this entire problem was the physics problem of an object on a slope
but have we? what is θ? we don’t know what this is, how do we calculate it?
we can do some vector math to solve for it. so θ is the angle respect to the vertical (the dotted line to the right of the angle). the vertical in this case is the opposite of where the normal force is going, and remember normal force is always perpendicular to the surface
if we knew the angle of the slope, then this would be easy but we are on a sphere where that angle is not easy to get, so we need another method
usually our normal force will match the up vector of the car, so we can just use that and invert it. now we now know our gravity force and the direction straight down relative to the surface, we can use a very useful vector equation called the dot product, you can see more examples of how useful the dot and cross product of vectors are here The Ultimate Guide to Vector3:Cross() and Vector3:Dot()
in our case we are going to use it to get an angle between the gravity force, and the y direction of the gravity force
this is Vector3:Dot(Vector3)
this gives the angle in radians, if you want to make sure the angle makes sense you can convert it to degrees by using math.deg
and printing it, but remember math.cos
and math.sin
require the angle to be in radians to process it correctly
your gravity force and inverted surface direction should be aligned on the same plane most of the time, so weird aligning wont give you an issue with the angle
now we have truly solved the problem. if anybody still reading this needs help ask me, i tried to explain it the best i could