Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to reduce the max turning angle of a car gradually as the car gains speed?

Asked by 3 years ago

I am not asking people to do the work for me necessarily, but I am hoping someone can point me in the right direction.

I am using the Roblox suspension tutorial car and I am experimenting with making it handle more realistically. One of the main things I want to do to it is to make the maximum turning angle of the car decrease slightly as the player drives faster. This would mean the car is more stable at higher speeds when trying to drive with the keyboard and it would mean the player can't just go round a corner flat out every time without slowing down.

I believe it is also how large games like Forza simulates the steering at speed.

I am pretty new to coding which is why I am more looking for someone to help me find the right sort of thing I need to look at and add than for someone to just throw me some code that I don't understand.

There is a section of the code that reduces torque as the car speeds up and I was messing around with trying to alter that to change the turning angle as well, however I didn't get very far, I just made the max turning angle decrease constantly while accelerating and it doesn't stop or go back up. It also affected the braking for some reason.

-- Accelerating
    elseif math.abs(throttle * currentVel) > 0 then
        -- Reduce torque with speed (if torque was constant, there would be a jerk reaching the target velocity)
        -- This also produces a reduction in speed when turning
        local r = math.abs(currentVel) / MAX_SPEED
        -- Torque should be more sensitive to input at low throttle than high, so square the "throttle" value
        motorTorque = math.exp( - 3 * r * r ) * TORQUE * throttle * throttle
        targetVel = math.sign(throttle) * 10000  -- Arbitrary large number

        -- Turn Angle Realism TESTING
        MAX_TURN_ANGLE = math.exp( - 1 * r * r) * MAX_TURN_ANGLE * throttle * throttle
        targetAngle = math.sign(throttle) * 10000
        print(MAX_TURN_ANGLE)
        wait(0.25)

I print the MAX_TURN_ANGLE every 0.25 seconds purely to monitor what the value is actually changing to as I accelerate although that wouldn't be in the final code as I imagine forcing the script to wait for 0.25 will be causing problems of it's own.

Apologies if I have laid this out the wrong way or put it in the wrong place, this is my first question of here. The rest of the code is still the same as the original code for the suspension car official tutorial, however, if you need me to add the full code because I have missed out a bit you need to help understand my problem then let me know and I can do that.

Again, I am not asking someone to do the work for me, I am looking for someone to help me understand what it is I need to learn and do to make this work one way or another.

Thank you.

Answer this question