Hi there,
I got this wee script that does most of the vehicle driving job rather well. However, when I am trying to drive a steep (not too steep really) slope, the engine shuts down (as intended). But when I power it on again, I just can’t climb up - my vehicle rolls down on wheels.
float acc;
if ((Input.GetAxis("Vertical") > 0.1f) || (Input.GetAxis("Vertical") < -0.1f))
{
acc = Input.GetAxis("Vertical");
}
else
{
var localVelocity = transform.InverseTransformDirection(rigidbody.velocity);
if (localVelocity.z > 0.05)
{
acc = -3f;
}
else if (localVelocity.z < -0.05)
{
acc = 3f;
}
else
{
acc = 0;
}
}
I tried something rather crude, a key binding to increase the acceleration - but its not exactly what I am looking for - once used, it will just shoot the vehicle forward - and a subsequent jump over the edge of the slope. What I am really looking for is a steady speed, slowly rolling the slope. I am using the wasd keys - and when I hit the critical point I want to use the shift like a really basic gearbox. Maybe I should look into motor torque instead (I did so with about the same results) or forward friction - if tat’s even a variable accessible in script?