Hello everyone, if / how I could make a non-kinematic rigid body be able to accelerate at a set rate regardless of drag. Essentially taking something like this:
thisRigidbody.AddForce (acellerationSpeed, ForceMode.Acceleration);
And having it become something like this:
thisRigidbody.AddForce (acellerationSpeed + the current Drag value retarding acceleration, ForceMode.Acceleration);
What I’m trying to achieve:
Essentially I have a non-kinematic rigid body boat, and I would like to be able to have it accelerate at a constant rate regardless of Drag up to a maximum speed (or a % of that max speed), but still have drag so that when the acceleration conditions are no longer met, the boat will slow down (and I can change how fast it does that with Drag).
You’ll see below that I have done a simple if / else where if the boat is accelerating the Drag is 0, then when the player is trying to slow down, Drag is applied. It works until the boat turns, and of course at that point since Drag is 0 it will drift endlessly…so it has some drawbacks.
void Update ()
{
if(slider.value > 0f && thisRigidbody.velocity.z < (maxSpeed * slider.value) && thisRigidbody.velocity.z < maxSpeed)
{
//thisRigidbody.drag = 0f;
time += Time.fixedDeltaTime;
//Debug.Log ("maxspeed * slider.value is:" + (maxSpeed * slider.value));
thisRigidbody.AddForce (acellerationSpeed, ForceMode.Acceleration);
}
/*
else if (thisRigidbody.velocity.z > (maxSpeed * slider.value))
{
thisRigidbody.drag = 0.2f;
}
*/
Debug.Log ("Current fixed time is: " + time);
Debug.Log ("Current Cube Velocity is: " + thisRigidbody.velocity);
}
Any ideas are appreciated, thank you for reading.