Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

how to calculate its speed

Discussion in 'Scripting' started by Michounours, Jun 3, 2015.

  1. Michounours

    Michounours

    Joined:
    Mar 10, 2015
    Posts:
    4
    Hi everyone,

    i'm building a car game and i will have several cars with different weight and size.
    So each car will have a different maxSpeed (for exemple 50 : carRigidbody.AddRelativeForce(0f, 0f, 50))
    This car velocity grow up and stabilize at 24.

    For other calculs, i need this max Velocity so i need to calcul it.
    Do you know how calculate this max Velocity depending upon weight ,size and maxSpeed (50) ???

    Thanks
     
  2. VesuvianPrime

    VesuvianPrime

    Joined:
    Feb 26, 2013
    Posts:
    135
    Can you do

    Code (CSharp):
    1. rididbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, 50);
     
  3. Michounours

    Michounours

    Joined:
    Mar 10, 2015
    Posts:
    4
    Thanks for help but it's not that i need.
    ClampMagnitude return a result when i'm driving but i need the maxVelocity before the car launch.

    when i accelerate : carRigidbody.AddRelativeForce(0f, 0f, 50)
    When the car is at the max speed : carRigidbody.velocity.z = 24
    but i want predict this value before acceleration