Edy's Vehicle Physics - official thread

Discussion in 'Assets and Asset Store' started by Edy, Jan 19, 2012.

  1. aglavarar

    aglavarar

    New Member

    Joined:
    Apr 23, 2013
    Messages:
    14
    Yes, i forget if your work is stable ..
    btw ,if i want the bus or model car SUV rollover in highspeed when turning..whether edy's physics able make it??
  2. erp.lsf

    erp.lsf

    New Member

    Joined:
    Apr 13, 2013
    Messages:
    7
    It's again me. I've played around for a little with your package, and managed to set up own car with your scripts, and so far, on smooth terrain it worked out pretty well, but I noticed one strange thing:
    [​IMG]
    See this pink lines? looks like something applies unneeded force to wheels, of wheels colliders are not configured properly. Anyways, I just can't understand where the problem is.
  3. Kreyg

    Kreyg

    Member

    Joined:
    Dec 31, 2012
    Messages:
    35
    How does one gain access to the C# scripts if they've purchased this?
  4. erp.lsf

    erp.lsf

    New Member

    Joined:
    Apr 13, 2013
    Messages:
    7
    Scripts are located in EdyVehiclePhysics folder of unitypackage.
  5. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    Your best option would be disable or reduce the force of the anti-roll bar components at the bus. Other options include raising the center of mass and increasing the tire's sideways friction.


    These pink lines appear when the suspension in the WheelCollider is compressed beyond its range. Possible causes include:
    - suspension distance too short.
    - suspension spring value too small.
  6. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
  7. erp.lsf

    erp.lsf

    New Member

    Joined:
    Apr 13, 2013
    Messages:
    7
    I've tried to tinker with spring values, and mass of car rigidbody, but now i get this lines got white an still pointing upwards(I noticed that with your prefabs, they're pointing downwards, so I thought this is not wanted behaviour).
    [​IMG]
    Or should I just tinker with car settings more?
  8. Bty

    Bty

    New Member

    Joined:
    Mar 14, 2013
    Messages:
    6


    Thank you, I played around with those two and adjusted the centre of gravity slightly down and forward, now my car is much better, not exactly drifting, but at least sliding with all 4 wheels nicely.

    One more question if I may. :)

    I'm making an arcadish game, while still keeping some realism in it. I'd like to add a parameter to make the rear wheels gain some grip if the back is sliding, in order to keep the car easily under control in big slides. unity car tutorial does this, the trick is to add grip to the rear wheels once they slip. Can you point me in the right direction?
    Last edited: May 3, 2013
  9. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    That's good. White lines represent the force supported by the springs on each tire. In the picture you can see that front wheels are supporting around twice the mass of the rear wheels. They also point upwards in my prefabs.

    The parameter sidewaysDriftFriction in CarControl is what you are looking for :)
  10. Bty

    Bty

    New Member

    Joined:
    Mar 14, 2013
    Messages:
    6
    Thank you
  11. ZiadJ

    ZiadJ

    Member

    Joined:
    Sep 3, 2011
    Messages:
    15
    I totally agree with Edy here Newlife. I won't say that your vehicle physics are not accurate but it really sucks when it comes to the feel of it. I can hardly notice your cars dodging sideways when taking turns or forward/backwards when braking/accelerating, as one would expect, making it feel very odd and unsatisfying at times. The same happens when running on moderate bumps also.

    It's more to do with the suspensions I think and I've spent a lot of time playing with their settings from your demo in vain up to now. I always end up frustrated with it being too rigid or "constrained" like Edy said it. So unless I badly need support for manual gears I'm definitely staying with Edy's package just for the more noticeable and natural response from the suspension and the overall feel of it.
    Last edited: May 9, 2013
  12. newlife

    newlife

    Member

    Joined:
    Jan 20, 2010
    Messages:
    556
    there is no constraint in UnityCar. If you try any other realistic simulator (try for example Carx demo for unity or rFactor) you'll notice the same kind of behaviour of UnityCar. Probably you are searching for a "bouncy" GTA4 behaviour, with exaggerated pitch (vertical tilting) and roll (lateral tilting). You can easily obtain this kind of behaviour lowering suspensions stiffness and increasing suspension travel to compensate.
  13. Enzign

    Enzign

    Member

    Joined:
    Aug 20, 2010
    Messages:
    155
    Very impressive package Edy. I have but one problem.

    When i drive up a ramp at an angle the car starts rotating clockwise. It also gets a velocity boost when i drive up a ramp, no matter if i drive at an angle or not. The steeper the angle of the ramp the more rotation and velocity is applied. It seems to be right after the back wheels come onto the ramp, and it is a backwheel driven car.
    Any idea what could cause this?

    EDIT: Seems to have been the "Forward Wheel Friction, Drift Slope" value that messed me up. Put it to 0 and it stopped rotating when driving onto a ramp.
    Last edited: May 14, 2013
  14. erp.lsf

    erp.lsf

    New Member

    Joined:
    Apr 13, 2013
    Messages:
    7
    Now, after I managed to get into flow with your great asset, I found another question which interests me:
    Is it possible/allowed to configure/modify your code to add support for more than 2-axis cars? And in advance, for n-axis cars?
    Or it is too hard/impossible?
  15. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    It might take some time but I don't think it's difficult. For instance, you could search CarControl for WheelFL, WheelFR, then add WheelFR2, WheelFR2 (for adding two additional front wheels). You will need to tweak the code a bit where WheelFL and WheelFR are actually used.

    A way for implementing n-axis cars could be to create an array of N objects each one including:


    • Reference to the Left and Right CarWheel objects (as current WheelFL, WheelFR, etc. do)
    • Amount of steer to apply to this axis (+1..0..-1). Negative values might be used, for example, at multi-axis cranes where the rear axis also have certain amount of steering.
    • Amount of throttle to apply to this axis (0..1).
    • Amount of brake to apply to this axis (0..1).

    Thus, when the CarControl script handles the motorInput value, you would go through each axis object multiplying motorInput with the amount of throttle, and applying the result to the corresponding left and right CarWheel objects. Same with steerInput and brakeInput.

    The CarVisuals script might need a most intense rework, but the basis would be the same.
    Hope this helps!
  16. erp.lsf

    erp.lsf

    New Member

    Joined:
    Apr 13, 2013
    Messages:
    7
    Thank you for your reply, Edy.
    I managed to translate all needed parts into n-axis variant in about hour of real time. For now I've using just N-elements array of WheelColliders/Pivots/Meshes - Object variant(with parameters is yet to come).
    In evening I'll test my work, and can give you some report if you're interested.
  17. Mikosss

    Mikosss

    New Member

    Joined:
    May 19, 2013
    Messages:
    1
    Hey Edy! I'm new in Unity. I have your package, but I have problem... How could you build it on Android? I'm getting a lot of errors while building on Android... What should be changed to get Android build?

    Edit: this is not actual image...

    Attached Files:

    Last edited: May 22, 2013
  18. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    Those errors are not related with Android, but with the fact that Unity confuses my Camera scripts with the ones from Standard Assets, so mine are not imported when the Standard Assets are present. You must import the package into an empty project and all scripts will be imported correctly.
  19. erp.lsf

    erp.lsf

    New Member

    Joined:
    Apr 13, 2013
    Messages:
    7
    Is there any way to manage output of wheels outside of your scripts? Because we are trying now to port our game to android using some proprietary joystick scripts, and only way we see to deal with output of the joystick, is manually manage every CarWheel behavior.
  20. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    You have two ways for controlling the vehicles:
    • Directly controlling each vehicle through the input parameters at CarControl: steerInput, motorInput, brakeInput, handbrakeInput.
    • Rewriting the function SendInput at CarMain. This is the function that reads the input from the user and sends it to the selected vehicle. You can place your propietary code there.
  21. itjunkii

    itjunkii

    New Member

    Joined:
    Dec 1, 2011
    Messages:
    29
    Hello,

    I am looking for someone to implement manual shifting to a latest edition of Edy's great package.

    Has anyone done this that might be interested in a quick side-job?

    PM if your interested, looking to do it ASAP.
  22. cops52

    cops52

    New Member

    Joined:
    Jun 11, 2013
    Messages:
    30
    Is there ai? I need a traffic script, and I was wondering if this did it.
  23. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    Here are some tips for implementing manual shifting.

    Before trying to do your implementation, I must warn you that it cannot be implemented in the regular way (decreasing the torque at the wheels) because of the (in)famous bug of the WheelCollider component. This bug causes incoherent behaviors at the wheel under certain conditions. One of them is that the wheel reduces the sideways friction when the torque is decreased. This causes the vehicle to loose the control at high speeds.

    I'd implement the manual gearbox as a list of values to specific parameters that limit the maximum speed on each gear. All these parameters are at the script CarControl:

    - motorMax: only for lower gears / low speeds (reduces the sideways grip).
    - airDrag: for limiting the top speed on each gear (keep motorMax at its full value).

    Switching gears would apply a set of values for those parameters. You would need also to adjust the CarSound script so the current gear is read from your values instead of calculated out of the wheel's spin rate.
  24. cat14air

    cat14air

    New Member

    Joined:
    Jun 22, 2013
    Messages:
    1
    hi,edy
    Do you have use vehicle dynamics?
  25. Crymek

    Crymek

    New Member

    Joined:
    Dec 23, 2011
    Messages:
    47
    Hello, I'm Chris and I have a problem.

    When I am with Bus and press a button to turn on a light, light is enabled at all cars. How to fix this ?
  26. Aron2hip

    Aron2hip

    New Member

    Joined:
    Jul 4, 2013
    Messages:
    7
    is there any way to start in a fps then utilize a trigger to enter then exit a car please help I'm trying to make a GTA style fps
  27. CTCCoco

    CTCCoco

    Member

    Joined:
    Feb 7, 2013
    Messages:
    19
    Mate, it would be possible to make a bicycle with your vehicle physics?
    Last edited: Jul 9, 2013
  28. jocarrillo

    jocarrillo

    New Member

    Joined:
    Jul 12, 2013
    Messages:
    1
    Thanks for the tips Eddy, I have implemented the Manual Transmission and it works nice! ;)
  29. omg_Aya

    omg_Aya

    New Member

    Joined:
    Jun 24, 2013
    Messages:
    1
    Hey Edy, can you check your email for me? I bought the package a week ago and still don't have access to the repo. I tried to send a private message on here but it said your inbox was full xD.
  30. juba08

    juba08

    Member

    Joined:
    Jul 8, 2013
    Messages:
    5
    Hi i am searching four hours where is Edy's Vehicle Physics default vehicle located but i could not find. I found var startupCar = 0; and private var m_currentCar = 0; variables but when i changed these nothing happened. Game choosed red car again.



    Related files: CarMain, CameraControl, CarControl, CarSettings
  31. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    I think I've already replied you, but sorry if not. I'm now catching up the email so you should receive your repo access shortly.
  32. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
  33. DragonByte

    DragonByte

    Member

    Joined:
    Sep 30, 2012
    Messages:
    14
    Bought it today, thanks!

    But translate your source code comments in english next time ;)
  34. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    I'm developing the upcoming Vehicle Physics product directly in C# and with comments in english :)

    (bumping the promo)
    -----
    Edy's Vehicle Physics is on Special Sale today!
    Grab your copy at half the price!


    https://www.assetstore.unity3d.com/#/content/403
  35. DragonByte

    DragonByte

    Member

    Joined:
    Sep 30, 2012
    Messages:
    14
    That's awesome :D

    BTW: If you have time, are you able to send me the GIT repository login information?
  36. rocki

    rocki

    Member

    Joined:
    Aug 10, 2012
    Messages:
    1,041
    Hey Edy,

    Great package. Have a few pre-buy questions.

    1. "I'm developing the upcoming Vehicle Physics product directly in C# and with comments in english ". If we buy this package, do we automatically get the new upgrade?

    2. I'm targeting mobile. How is the performance for mobile?

    Thanks.
  37. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    Sure, send the invoice number to edytado@gmail.com

    1. No, this will be a different product. It will use a radically different and innovative approach for simulating fully realistic tire forces. Both products will be available at the Asset Store.

    2. Here are two good examples:
    http://www.edy.es/dev/2013/04/duty-driver-for-android/
    http://www.edy.es/dev/2012/07/a-success-history-on-iphone/
  38. rocki

    rocki

    Member

    Joined:
    Aug 10, 2012
    Messages:
    1,041
    Nice examples.

    When do you think the release date will be for the new product and how much will it be?
  39. lyndontroy

    lyndontroy

    New Member

    Joined:
    Dec 12, 2012
    Messages:
    13
    I bought the Vehicle Physics today and I get errors with the "CameraControl.js" file. I am running Unity Pro 4.2.of4 on my new Mac. Please help.

    This is the log file:


    Assets/EdyVehiclePhysics/CameraControl.js(45,33): BCE0018: The name 'CamSmoothFollow' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 45)

    Assets/EdyVehiclePhysics/CameraControl.js(46,31): BCE0018: The name 'CamMouseOrbit' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 46)

    Assets/EdyVehiclePhysics/CameraControl.js(47,33): BCE0018: The name 'CamSmoothLookAt' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 47)

    Assets/EdyVehiclePhysics/CameraControl.js(52,30): BCE0018: The name 'CamSmoothFollow' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 52)

    Error: Analytics Event: 5(Compiler*BCE0018*The name 'CamSmoothFollow' does not denote a valid type ('not found'). )(1): skipped because it was sent more than once in 0.10 seconds
    Assets/EdyVehiclePhysics/CameraControl.js(228,62): BCE0018: The name 'CamSmoothFollow' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 228)

    Assets/EdyVehiclePhysics/CameraControl.js(229,58): BCE0018: The name 'CamMouseOrbit' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 229)

    Assets/EdyVehiclePhysics/CameraControl.js(230,62): BCE0018: The name 'CamSmoothLookAt' does not denote a valid type ('not found').

    (Filename: Assets/EdyVehiclePhysics/CameraControl.js Line: 230)

    Assets/EdyVehiclePhysics/CameraControl.js(243,77): BCE0018: The name 'CamSmoothFollow' does not denote a valid type ('not found').
    Last edited: Jul 31, 2013
  40. lyndontroy

    lyndontroy

    New Member

    Joined:
    Dec 12, 2012
    Messages:
    13
  41. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    I can't tell. I expect to have prototypes ready to show in a few months.

    For some reason beyond my understanding Unity keeps confusing my own camera scripts with those from the Standard Assets. So as you already have the Standard Assets in your scene, Unity won't even show mine in the Import dialog. Weird.

    Create an empty proyect, import Vehicle Physics there. Open your project, and move the missing scripts from the other project to yours. You can keep two Unity instances opened with different projects (hold Alt or Cmd while opening Unity).

    Send the invoice number to edytado@gmail.com and I'll reply you with full instructions.
    Please be patient, I'm having many requests today :)
  42. lyndontroy

    lyndontroy

    New Member

    Joined:
    Dec 12, 2012
    Messages:
    13
    Thank you for the prompt reply. Works fine now.
  43. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,107
    i'm getting the following errors

    "You are trying to import an asset which contains a global game manager. This is not allowed."

    "can't use image filters (npot-RT are not supported or RT are disabled completely)"

    using unity 4.2 latest
    using latest edy's vehicle physics

    thanks in advance!
    Last edited: Jul 31, 2013
  44. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,107
    Please Help!

    First online web browser demo works great, but i'm having a problem the version that i got. In addition to the errors i cited above when I open a new project with this asset, I'm having intermittent problems with the vehicles in demo scene "TheCity".

    Basically what happens is after a sudden stop like in a crash the vehicle will not move forward/reverse in response to keyboard input for a few seconds. no engine noises. Motor Input = 0 and Break Input = 1 and vehicle is in Neutral, even though I'm not pressing the key to break and I'm only pressing the key to move forward or backwards. The problem resolves when I stop pressing any forward/reverse keys, wait a second or so and then try again. This is very awkward to say the least and will hopefully be fixed soon since as it is it is not something that can be shipped in any game without having customers complain about it.

    I honestly do not want to wade through your code looking why Motor Input is being set to 0 and Break Input is being set to 1 and and vehicle is stuck in Neutral when I am pressing the forward or backwards keys.

    I'm using latest Unity 4.2 and perhaps the webbrowser demo version is different than the latest version that I downloaded from Unity Asset Store.

    Thanks In advance!

    Update 1: I may have found work around by enabling "Read User Input". Since I just bought the package very late last night I'm not sure what it means, but hope it helps... Still there is a problem and the vehicle should not behave as I described above to user input. If the car is like stalled which I'm not sure is what is happening it should at least make some noise like it's being started or something.

    Update 2: I did more testing because your name has the letter 'y' in it ;) and I found that if you disable "Reverse Requires Stop" the problem does not occur! Now I know what your thinking already. But it ain't so the vehicles are completely stopped! So its not cause they r moving at all and the delay is beyond what would be needed in any real vehicle and quite noticeable... So, it's a bug in need of a fix!
    Last edited: Aug 1, 2013
  45. blaze

    blaze

    Member

    Joined:
    Dec 21, 2011
    Messages:
    212
    I'm with the same problem. Waiting for some fix.
  46. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,107
    Hello again,

    Please add support for a speedometer and please add speedometer in future release. On HUD on optionally in-vehicle.

    Also, is there a way to specify a specific sound(s) when the vehicle is turned on or turned of?

    Also, is there a way to specify a specific sound(s) when it crashes?

    Also, is there the concept of vehicle stalling for whatever the reason, for example when it crashes?

    Also, when the vehicle crashes is there a way to have the glass break? Have glass breaking sound, effects. I guess the regular glass could just be hidden. If not something that it currently can do can it then be added to some future release?

    Also, if the vehicle is severely damaged like in a crash does the engine, transmissions, breaks stop working or work in a degraded way? If so how can this be specified else can this be added?

    Finally, if the vehicle is severely damaged like in crash can it emit smoke and even fire and blow up? If not would it be possible to add to future release.

    I guess what I'm saying is vehicles are not complete with like more realistic damage than just mesh effects and it would be really nice if some future released dealt with it.

    Again thanks in advance!
  47. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,107
    try one of these workaround i found by playing around!

    Last edited: Aug 1, 2013
  48. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,107
    Hello again and again!

    I just bought Speedometer UI and I'm trying to hook it up any help would be appreciated!

    https://www.assetstore.unity3d.com/#/content/1008

    Also, I bought Extreme Vehicle Pack and I'm trying to hook up the vehicles any help would also be greatly appreciated.

    https://www.assetstore.unity3d.com/#/content/8344

    If anyone has done the above why not release it to the public so that Edy can just bundle it in with this this and we all can benefit from it instead of doing it again and again and again!

    As always thanks in advance!

    P.S. Also please include complete documentation with the release. I know its at your website, but still... :)

    Update 1: I did the code to interface Edy Vehicle Physics with Speedometer UI, but like everything in life worth doing, I ran into a problem. The problem is basically Edy's stuff is written in JavaScript and Speedometer UI in C# and in Unity3d there is no easy way for C# to access JavaScript classes and functions :( So, sad. So I'm going to have to switch to Edy's C# implementation and have a go at it again...

    Update 2: Just finished creating SpeedometerInterface for Edy Vehicle Physics C# and Speedometer UI and so far looking good. Now the question should we give it away for free, or should we make people pay a $1 towards my retirement for it or worse should we do something evil like ask people to create and post a video on YouTube.com with you singing the STAR SPANGLED BANNER in order of get a copy?

    Surely you could do better than this guy...
    www.youtube.com/watch?v=8SHnpWohrg0

    Update 3: Since nobody will sing for me the STAR SPANGLED BANNER, I guess asking for $1 towards my retirement is out of the question as well. So I'll have to give it away for free and retire homeless and destitute!

    Just add to <project>\Assets\EdyVehiclePhysics\CSharp\SpeedometerInterface.cs
    Then follow instruction in the comments.

    Warning. this code my not be correct, I'm still playing with it, but it at leasts makes the dial move about right. I'm still not certain about engine RPM and Turbo, so if anyone finds a bug, please post the fix!

    Code (csharp):
    1.  
    2. /*
    3. * DO NOT OBSCURE, ALTER OR REMOVE THIS NOTICE FROM THIS OR ANY MODIFIED OR DERIVED VERSIONS!
    4. *
    5. * Copyright (C) 2013 me. All Rights Reserved.
    6. *
    7. * This source code is free software; you can redistribute it and/or
    8. * modify it under the terms of the GNU Lesser General Public
    9. * License as published by the Free Software Foundation; either
    10. * version 2.1 of the License, or (at your option) any later version.
    11. *
    12. * This source code is distributed in the hope that it will be useful,
    13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    15. * Lesser General Public License for more details.
    16. *
    17. * You can receive a copy of the GNU Lesser General Public License from
    18. * http://www.gnu.org/
    19. */
    20.  
    21. using UnityEngine;
    22. using System.Collections;
    23.  
    24. /*
    25.  * This class is used to update the Speedometer UI with values from the the current vehicle.
    26.  *
    27.  * Please note that this interface only works with Eby Vehicle Physics C# implementation.
    28.  *
    29.  * 1.   To use import both Eby Vehicle Physics C# asset
    30.  *      and Speedometer UI asset.
    31.  *
    32.  * 2.   Then add to the object that contains the "Car Main (Script)", the CarMain Script,
    33.  *      normally MAIN object, an empty GameObject and name it SpeedometerUI.
    34.  *
    35.  * 3.   Then to the SpeedometerUI object that you just created
    36.  *      add one or more SpeedometerUI C# and configure them as needed.
    37.  *
    38.  * 4.   Then add to the object that contains the "Car Main (Script)", the CarMain Script,
    39.  *      normally MAIN object, a "Speedometer Interface (Script)", the SpeedometerInterface Script.
    40.  *
    41.  * 5.   Finally set the "Speedometer UI" property in "Speedometer Interface (Script)",
    42.  *      the SpeedometerInterface Script, to the SpeedometerUI object that is found
    43.  *      in the object that contains the "Car Main (Script)", the CarMain Script,
    44.  *      normally MAIN object.
    45.  */
    46.  
    47. public class SpeedometerInterface : MonoBehaviour
    48. {
    49.     public SpeedometerUI speedometerUI;
    50.    
    51.     public CarControl GetCar()
    52.     {
    53.         CarMain carMain = GetComponent <CarMain>();
    54.         CarControl car = carMain.getSelectedCar();
    55.         return car;
    56.     }
    57.  
    58.     CarSound GetCarSound(CarControl car)
    59.     {
    60.         CarSound carSound = car.GetComponent<CarSound>();  
    61.         return carSound;
    62.     }
    63.    
    64.     float GetSpeedInMS(CarControl car)
    65.     {
    66.         return new Vector2(Vector3.Dot(car.rigidbody.velocity, car.transform.forward), Vector3.Dot(car.rigidbody.velocity, car.transform.right)).magnitude;
    67.     }
    68.    
    69.     public float GetSpeedInKPS(CarControl car)
    70.     {
    71.         return GetSpeedInMS(car) * 3.6f;
    72.     }
    73.        
    74.     public float GetSpeedInMPH(CarControl car)
    75.     {
    76.         return GetSpeedInMS(car) * 2.237f;
    77.     }
    78.    
    79.     public string GetCarGearAsString(CarControl car)
    80.     {
    81.         string carGear;
    82.        
    83.         CarSound carSound = GetCarSound(car);
    84.         if (carSound == null)
    85.         {
    86.             // I am assuming that this means that the engine is off
    87.             carGear = car.getGear();
    88.         }
    89.         else
    90.         {
    91.             int gear = carSound.currentGear;
    92.            
    93.             carGear = (gear > 0) ? gear.ToString() : (gear < 0) ? "R" : "N";
    94.         }
    95.        
    96.         return carGear;
    97.     }
    98.    
    99.     public int GetCarGearAsNumber(CarControl car)
    100.     {
    101.         int gear;
    102.        
    103.         CarSound carSound = GetCarSound(car);
    104.         if (carSound == null)
    105.         {
    106.             // I am assuming that this means that the engine is off
    107.             gear = car.gearInput;
    108.         }
    109.         else
    110.         {
    111.             gear = carSound.currentGear;
    112.         }
    113.    
    114.         return gear;
    115.     }
    116.    
    117.     float GetMinimumRPM(CarControl car)
    118.     {
    119.         float engineRPM;
    120.        
    121.         CarSound carSound = GetCarSound(car);
    122.         if (carSound == null)
    123.         {
    124.             // I am assuming that this means that the engine is off
    125.             // we should switch to EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm) / 2 * GearRatio[CurrentGear];
    126.             engineRPM = 0;
    127.         }
    128.         else
    129.         {
    130.             engineRPM = carSound.engineIdleRPM;
    131.         }
    132.        
    133.         return engineRPM;
    134.     }
    135.    
    136.     public float GetRPM(CarControl car)
    137.     {
    138.         float engineRPM;
    139.        
    140.         CarSound carSound = GetCarSound(car);
    141.         if (carSound == null)
    142.         {
    143.             // I am assuming that this means that the engine is off
    144.             // we should switch to EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm) / 2 * GearRatio[CurrentGear];
    145.             engineRPM = 0;
    146.         }
    147.         else
    148.         {
    149.             engineRPM = carSound.engineRPM;
    150.         }
    151.        
    152.         return engineRPM;
    153.     }
    154.    
    155.     public float GetTurboRPM(CarControl car)
    156.     {
    157.         float turboRPM;
    158.        
    159.         CarSound carSound = GetCarSound(car);
    160.         if (carSound == null)
    161.         {
    162.             // I am assuming that this means that the engine is off
    163.             turboRPM = 0;
    164.         }
    165.         else
    166.         {
    167.             if(carSound.EngineExtraAudio)
    168.             {
    169.                 // I am assuming that any extra rpms is due to the turbo
    170.                 // we should switch to EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm) / 2 * GearRatio[CurrentGear];
    171.                 turboRPM = GetRPM(car) - carSound.engineMaxRPM;
    172.             }
    173.             else
    174.             {
    175.                 // I am assuming that this means that the vehicle does not have a turbo installed
    176.                 turboRPM = 0;
    177.             }
    178.         }
    179.        
    180.         return turboRPM;
    181.     }
    182.    
    183.     void Update()
    184.     {
    185.         if (speedometerUI != null)
    186.         {
    187.             CarControl car = GetCar();
    188.            
    189.             SpeedometerUI[] speedometerIUs = speedometerUI.GetComponents<SpeedometerUI>();
    190.            
    191.             foreach (SpeedometerUI oSUI in speedometerIUs)
    192.             {
    193.                 if (oSUI.ControlName == "Speed")
    194.                 {
    195.                     oSUI.Speed = GetSpeedInKPS(car);
    196.                     oSUI.Gear = GetCarGearAsString(car);
    197.                 }
    198.                 else if (oSUI.ControlName == "Turbo" )
    199.                 {
    200.                     oSUI.Speed = GetTurboRPM(car);
    201.                 }
    202.                 else if (oSUI.ControlName == "RPM")
    203.                 {
    204.                     oSUI.Speed = GetRPM(car);
    205.                 }
    206.                 else if (oSUI.ControlName == "" || oSUI.ControlName == "ALL")
    207.                 {
    208.                     oSUI.Speed = GetSpeedInKPS(car);
    209.                     oSUI.Gear = GetCarGearAsString(car);
    210.                     oSUI.RPM = GetRPM(car);
    211.                 }
    212.             }
    213.         }
    214.     }
    215. }
    216.  
    Last edited: Aug 1, 2013
  49. blaze

    blaze

    Member

    Joined:
    Dec 21, 2011
    Messages:
    212
    Thank you!
    I will try on the weekend.
  50. Edy

    Edy

    Member

    Joined:
    Jun 3, 2010
    Messages:
    257
    This behavior is by design. I like to be able to stop the car in the middle of a slope without the reverse gear pushing the vehicle backwards immediately. The instructions below the live demo read:

    Gears: Changing from forward (D) to reverse (R) and vice-versa requires the car to completely stop and then release both accelerate and brake keys, then press accelerate (forward) or brake (reverse). This behavior can be customized for each project (see the documentation for the CarMain script).

    The vehicle can be configured to a more traditional control by disabling the property reverseRequiresStop in CarMain (or in CarControl when readUserInput is true).

    reverseRequiresStop:
    Configures the stop and reverse behavior. If enabled, car is required to completely stop, then releasing and pressing the brake key again in order to go reverse.