Search Unity

Animation curve: speed vs time

Discussion in 'Scripting' started by SomerenV, Aug 28, 2020.

  1. SomerenV

    SomerenV

    Joined:
    Dec 20, 2011
    Posts:
    83
    I've got a vehicle which currently uses a hard to understand torque value (some number that means nothing in the real world) so I thought it would be better to tell the vehicle how fast it's supposed to be moving instead of calculating it's speed using arbitrary numbers.

    Here's an example:



    So it should take 5 seconds to get to 100kmh, 20 to get to 200 and 250 is about the maximum it can go. Right now I've got a torquecurve puts out a certain value by evaluating the speed, but it's really hard to get the car to accelerate in a realistic way.

    The wheels are being 'moved' by rigidbody.AddForceAtPosition. Right now it's using transform.forward, the torque from the engine, forwardgrip and a hit.point. What I want to do is tell the wheels to go fast enough to reach 100 in 5 seconds for example (like in the curve above).

    So:
    - How do I evaluate speed against time?
    - How do I make sure that output gets send correctly to the wheels?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    If you want a specific numeric output, don't use physics. Just set the speed as a function of time. Otherwise you will NEVER get it right. This is because the physics system creates results as the consequence of many small iterations summed up over time, and the inputs include masses, frictions, drag, angular inertia, etc.

    Use the formula for ratio of radius to circumference to decide how far to rotate your wheels so they look right.