@ Sven
So you're going to make me use the old coconut, huh? I wish I remembered physics a little better but I'll take a stab at your question.
I think it will help Soroki too. But, test out what I say because I'm definately no expert.
What I think you're talking about is centripetal and centrifugal forces. These act in opposite directions keeping the object moving in a circle along it's track without moving inward or outward. If you've already got your speed (it really should be velocity implying speed and direction), and your mass, you'll need two or three more things depending on how you want to handle it.
1. the radius of your circle or your curve
2. a slip-force variable that you choose - when exceeded, your car will slip sideways
3. and - depending on how you want to do the simulation - some kind of friction variable
For this example, we'll use a friction variable.
I created a function for the centripetal force which is directed toward the center of the circle:
rem Centripetal Force - Force directed towards center of rotation
rem it's just enough to keep the object going in a circle
function centripetal(mass#,velocity#,radius#)
force#=(mass#*(velocity#^2))/radius#)*-1
endfunction force#
The centrifugal force is directed AWAY from the center of the circle - compare this force to your slip force. But to keep the car going in a circle, they are equal.
This is where you could use the friction coefficient (variable). Let's say the car with a certain mass is turning at a certain speed. You could always treat the radius as 1, and the determinations of your force could be speed and mass.
Your program calculates the centrifugal force + your friction variable. If the total is greater than the slip-force, then you make the car slide.
Now I'm assuming you have a radius - This is important because the forces are less as the radius increases. So always treating the radius as 1 makes things nice and easy, but the slip would always be at the same speed.
But if you don't have a radius this is where things can get complicated. Calculating an unknown radius can be done, but you need other information to do it.
Note* If you are using atanfull() in your calculations, the angles are going to be clockwise and the calculations I'm gonna provide are counter-clockwise - the principals should be the same, you'd just have to switch your x and y in the atanfull() function (i.e. atanfull(y,x) ).
The first thing we need is to calculate how far one rotation of a wheel on the car is. You can make up a radius for this relative to the size of the 3d world. Let's say we use 7.
rem pi
function pi()
pi#=3.141592654
endfunction pi#
rem wheel rotation - just use the circumference of a circle
function wheelrotation(radius#)
distance#=2*radius#*pi()
endfunction
Our rotation length is ~44 units.
So we assume now that every time the car moves, it covers a distance of speed# * 44. This becomes important later. If the car wheels are turned, it's going to move in an arc at speed# * 44 at whatever angle. This is enough information to find out what the radius of the circle it would be traveling on is.
rem get radius from the arc of a circle
function getRfromARC(angle#,length#)
radius#=length#/(angle#*(pi()/180))
endfunction radius#
This function should calculate our radius. I had to convert degrees to radians inside the function to keep things consistant.
If the car is turning at 5 degrees and going at a speed of 1, the radius of our circle should be: 44/5*(pi()/180) = 505.75 This seems huge but it would be adjusted based on the scale of your world. And if the wheels were turned at 50 degrees (a tighter turn) then the radius would be 50.6.
Anyway, now that we have the radius of the circle the car is going around, we can apply it to the centripetal and centrifugal forces.
if our mass#=10
our speed#=1
our radius = ~506, What's our cetripetal, and centrifugal forces?
rem Centripetal Force - Force directed towards center of rotation
rem it's just enough to keep the object going in a circle
function centripetal(mass#,velocity#,radius#)
force#=(mass#*(velocity#^2))/radius#)*-1
endfunction force#
rem Centrifugal Force
function centrifugal(mass#,velocity#,radius#)
force#=((mass#*(velocity#^2))/radius#)
endfunction force#
centripetal = ((10 * (1^2))/506)*-1 = -.02
centrifugal = .02
Now if we have our friction variable set to .5 for example, and our slip_force = 2,
We want to do a comparison to see if our car is slipping:
if centrifugal + friction >= slip_force
goto to the slide car routine
centrifugal + friction = .02 + .5 = .52
.52 < slip_force = our car is not sliding
Ok. Mass will be constant. But speed and radius can change. How fast do we have to go at the same angle for the car to slip?
mass=10
speed=10
radius =~506
friction = .5
(10*10^2)/506 = 1.976 1.976 + friction = 2.476 = our car is sliding
Looks like in this scenario, a speed of about 10 would cause the car to slide.
Now you just have find the velocity vector (speed and direction) of the car and the tangent to that times the difference between centripetal and [centrifugal + friction] forces, and calculate the position of where the car would end up.
Enjoy your day.