Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Randomation Vehicle Physics 2.0 - Now open source on GitHub!

Discussion in 'Assets and Asset Store' started by JustInvoke, Mar 14, 2015.

  1. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Hi @RandomationGames
    Now, if i want to drift car, i must hold on the handbrake button to drift, and its need hold a time to drift car. If i want to press any button (like F button), and car will drift immediately that don't need hold a time on the handbrake button. Because some time it quite difficult to drift car. How can i do it ? Thanks you.
     
  2. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    The ebrake drifting behavior is a result of the friction behavior in the wheels. If the wheel stops spinning because the ebrake is applied, it is now slipping freely and has no traction, so it will also slide sideways resulting in drifting (The slip dependence variable can disable this). The same thing can happen when a wheel loses grip from excessive torque. By default the rear wheels on the prefabs have lower sideways friction to make drifting easier.

    Sliding bevavior depends on the friction curves. The peak in the curve is basically what the friction is when the wheel isn't slipping and still has control. After that is what the friction is while sliding.

    What you want to do is basically override the natural friction behavior and initiate drifting with the press of a button. What you could do is reduce the sideways friction of the rear wheels for a few frames when a button is pressed (this is the number indicating friction, not the curve). That way the vehicle will slide more readily only when the button is pressed.

    You can do this with a basic script containing an array of wheels to affect and a coroutine or timer variable that is initiated with a button press. When the coroutine ends or the timer variable reaches zero the friction of each wheel can be reset to their initial value.
     
  3. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Thanks for @RandomationGames reply.
    But Could you write some example code if do follow this way ? Example only. Thanks you so much.
     
  4. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    Ok, something like this might work (untested C#):
    Code (csharp):
    1.  
    2. public Wheel[] driftWheels;//Wheels to have friction reduced
    3. public string driftButton;//Input manager button for drift
    4. public float driftFriction;//Friction of wheels during drift
    5. float[] initialFrictions;//Initial frictions of each wheel
    6. public float driftTimeSet;//Duration of drift friction in seconds
    7. float driftTimer;//Time left for drift friction
    8.  
    9. void Start()
    10. {
    11.     initialFrictions = new float[driftWheels.Length];
    12.     for (int i = 0; i < driftWheels.Length; i++)
    13.     {
    14.         initialFrictions[i] = driftWheels[i].sidewaysFriction;
    15.     }
    16. }
    17.  
    18. void Update()
    19. {
    20.     driftTimer = Mathf.Max(0, driftTimer - Time.deltaTime);
    21.  
    22.     if (Input.GetButtonDown(driftButton))
    23.     {
    24.         driftTimer = driftTimeSet;
    25.     }
    26.  
    27.     for (int i = 0; i < driftWheels.Length; i++)
    28.     {
    29.         driftWheels[i].sidewaysFriction = driftTimer > 0 ? driftFriction : initialFrictions[i];
    30.     }
    31. }
    32.  
     
  5. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    Version 2.09 has been released with the following changes:

    New damageable “Fancy Kart” prefab.

    New scene with example of terrain using the TerrainSurface script.

    GearboxTransmission – 10% increase to auto-calculated RPM ranges.

    VehicleDamage – Default strength is zero instead of one.

    Suspension – Camber curve is now a flat line on all vehicle prefabs, meaning no camber change by
    default.

    New “camber offset” variable to change camber without using the curve.

    Steering angle properly recenters when min and max steer range are not equal opposites (Both values
    must still have opposite signs to work properly).

    VehicleMenu – RPM meter range is now correct regardless of motor sound pitch range.

    CameraControl – Fixed bug with upwards direction of camera and raycast mask.

    FollowAI – Removed limit that forced speed of vehicle to be equal to the initial speed, so now chasing
    cars can have their speed changed in play mode.

    Fixes to buggy steering/reversing behavior.

    New “target velocity” variable acts as a limit on the speed of a vehicle in meters per second.
     
  6. arnesso

    arnesso

    Joined:
    Mar 3, 2015
    Posts:
    96
    Hi,
    Has anyone tried this great asset with UFPS ? UFPS player will be able to get in the car .
    Cheers ! :)
     
  7. ian_facepunch

    ian_facepunch

    Joined:
    Mar 16, 2015
    Posts:
    22
    What's the best way to handle scaling up a vehicle? From the manual it says "If you want to scale a vehicle, the meshes must be scaled up on import, and the suspensions moved to the correct positions."

    I have a vehicle that is about 3 times the size of the Drift Car prefab in my current world scale. If I move the suspension parts and increase the wheel radius to match the size I want the vehicle predictably doesn't drive in the same way. The gas motor script now reports a vehicle top speed of 480 mph because of the increased wheel size.

    Is the best way to reduce my world scale to better match the prefabs / scripts found in the package?
     
  8. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    You should reduce your world scale, in Unity in general it is best practice to treat one unit as one meter. I assume your car is supposed to be "normal sized" as far as vehicles go.

    Increasing wheel size increases top speed because one full rotation of a wheel will result in greater distance traveled compared to a smaller wheel.
     
  9. ian_facepunch

    ian_facepunch

    Joined:
    Mar 16, 2015
    Posts:
    22
    It wasn't just the top speed that seemed to change, it was more that the vehicle became unresponsive and unstable.

    Anyway I've now reduced to a one unit / one meter scale and have the vehicle driving as expected :)

    Ian
     
  10. Deleted User

    Deleted User

    Guest

    Alright, I'm using the new update, and I'm having a bit of trouble with my 2.5D platformer.
    What I want the vehicle to do is only move along the Y and Z axis, but not the X, and only to rotate along the X and Z, not the Y.

    I've tried locking the Rigidbody, but after a while the vehicle always starts acting up (spinning etc.) - Is there a way to actually do this? Or is it up to Unity's phyiscs system.



    http://picpaste.com/GIF-f2RSadpp.gif

    I hope you get what I'm talking about.

    Cheers
     
  11. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    If you are moving on the YZ plane, you should only allow the vehicle to rotate on the X-axis. Allowing two axes of rotation can result in offsets on the third. Make sure to disable the SteeringControl script and set the sideways friction of the wheels to zero, since the forces from these scripts can cause problems with the movement restrictions.
     
  12. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Hi @RandomationGames , RVP 2 can make car "Tuning" like this car in NFS 2016 (Please see at 1:45s) ? If yes, how we can implement this features. Thanks you.

    This car tuning very cool ! We would like to see this tuning include in the RVP 2
     
    Last edited: May 29, 2016
  13. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    You can make a car drift like that, but it's hard to say exactly what the friction settings should be without experimenting first. For example, making adjustments based on the current drifting behavior of your vehicle. Do you have a vehicle set up that you want to tweak for drifting like this?
     
  14. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    I did try to setting for car drifting like this, but unfortunately !, still not successful to same this. Car always rotate a > 60 degree when drifting. As you can see in this video, car always rotate a 30 degree with the front car. It look very cool. If you have a solution to setting or make behaviour like car in this video. Please help ! Thank you.
     
  15. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    You could try increasing the falloff sideways friction on the rear wheels. You can do this by raising the rightmost key on the curve, so that the portion that's roughly a flat line is moved up. This makes it so the wheels won't lose as much friction while sliding, and maybe the car won't turn as much.

    If you are still having problems can you post a video or send me the project through e-mail?
     
  16. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Thanks for your help ! I did try but still not successful yet. I hope you will make a car prefab like this and put to the kit on the next update. I will waiting for it ! Thank your work, @RandomationGames

    P/s: If no, could you send to me the configured car via email ? Thanks in advanced !
     
    Last edited: May 31, 2016
  17. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    I would have to send you a unity package with the car in it, and I don't know your e-mail. You can PM it to me or e-mail me first.
     
  18. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Hi @RandomationGames

    I did sent you a PM. Could you check it, please !
     
  19. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Hello, @RandomationGames.
    We're making a game with traffic. The problem is, when there is a lot of cars (10-20+), FixedUpdate in Wheel class are eating up FPS. It drops to 2-3 fps, and there is 13k functions calls.
    Is this intended behaviour or is it a bug? Version is 2.02, because there are some changes made to the in this version Asset (shaders and custom function for drifting).
     
  20. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    In version 2.07 I added options for distributing raycasts across multiple frames so that for example, a 4-wheeled car can just do one raycast for each wheel across 4 frames. This makes the physics less precise and would be best for traffic vehicles rather than player-controlled ones. Support for variable fixed timesteps was also added.

    I've done as much as I can to optimize the raycasting, since in the end I can't make the raycast function any faster. Unfortunately you will have to update in order to use the new optimizations.
     
  21. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Thanks for the quick and informative answer! We're basically done with porting out project to new version of Randomation, but there is one little issue: vehicles debugging (restarting position) even if VehicleDebug script isn't attached to them. Can the reason behind this be that all vehicles use FollowAI logic, chasing after target?
     
    Last edited: Jun 8, 2016
  22. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    The FollowAI script is probably it, since vehicles will reset either from being rolled over or getting stuck. You can set the "roll reset time" or "reset reverse count" to -1 to disable them.
     
  23. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Yeah, it took some time (heed is not my best friend), but we found it out. Yet again, thanks for quick answer!
     
  24. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Here's my stats when debugging on android device, main load on cpu is wheel's FixedUpdates and Raycasts from our FollowAI: http://i.imgur.com/mzNgVa4.png
    Can you give any advice on how can we optimize this? If you need more info, I can PM you.
     
  25. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    Like I said, your only options are either increasing the fixed timestep or using the wheel groups on VehicleParent.
     
  26. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Can you give a litle more info about wheel groups? What I need to do in order to enable wheel groups? I uncommented all stuff in VehicleParent to enable wheelGroups, what else I need to do? Sorry for bothering you, but I'm complete amateur in Unity and programming in general, so it's hard for me.
    I have a problem adding elemetns to wheelgroup.
    Here I'm declaring new WheelGroup made of 4 elements.
    vehicleParent.wheelGroups = new WheelCheckGroup[4];
    But how do I add wheels to it?
    vehicleParent.wheels = new Wheel[4];
    vehicleParent.wheels [0] = suspensionFL.wheel;
    vehicleParent.wheels [1] = suspensionFR.wheel;
    vehicleParent.wheels [2] = suspensionRL.wheel;
    vehicleParent.wheels [3] = suspensionRR.wheel;
    Here is the part of code that adds wheels to the car.
    I understand that I need to add one Wheel in the each element of Wheelgroup, but I get error because of different types.

    Here's what I'm trying to do, where I gone to the wrong path?
    vehicleParent.wheelGroups = new WheelCheckGroup[4];
    vehicleParent.wheelGroups[0].wheels[0] = vehicleParent.wheels[0];
    vehicleParent.wheelGroups[1].wheels[1] = vehicleParent.wheels[1];
    vehicleParent.wheelGroups[2].wheels[2] = vehicleParent.wheels[2];
    vehicleParent.wheelGroups[3].wheels[3] = vehicleParent.wheels[3];

    I get NullReference error in vehicleParent.wheelGroups[0].wheels[0] = vehicleParent.wheels[0];
     
    Last edited: Jun 10, 2016
  27. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    You should set the wheel groups in the inspector since you're new to this. Each element in the array of wheel groups represents one fixed update step. You can have one wheel per update by having four groups, place one wheel in each group's array of wheels. The cars on the track in the mobile demo scene use wheel groups as an example.
     
  28. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    Sorry for the double post, but I want to have a post dedicated to announcing my plans for the future of the asset.

    I'm am probably going to stop selling the asset by the end of the month and cease updates altogether. I plan on dropping support after 2016 is over. I know on the previous page I said I would support it for the life of Unity 5.x, but due to unrelated life choices I must move on from asset development/support on my own timeline and not Unity's. This way even customers who purchase it just before it's taken down will still have 6 months of support.

    I understand some customers might be disappointed and I want to hear feedback, but the plans are pretty much set in stone.
     
  29. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    I can't set the wheel groups in the inspector since cars created by script. Is there a way to st groups by script too?
    Maybe you can give a little example of how to set wheel groups in the script?
     
  30. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    You should be able to do it through script. For setting the wheels array, you can just use GetComponentsInChildren<Wheel>(). What you did otherwise should work, except the wheelgroups.wheels array needs to be initialized as well, with something like VehicleParent.wheelGroups[0].wheels = new Wheel[1];
     
  31. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    I don't get how to use GetComponentsInChildren<Wheel>().
    What I tried to do:
    vehicleParent.wheelGroups[0].wheels = new Wheel[1];
    vehicleParent.wheelGroups[0].wheels[0] = suspensionFL.wheel;

    vehicleParent.wheelGroups[1].wheels = new Wheel[1];
    vehicleParent.wheelGroups[1].wheels[1] = suspensionFR.wheel;

    vehicleParent.wheelGroups[2].wheels = new Wheel[1];
    vehicleParent.wheelGroups[2].wheels[2] = suspensionRL.wheel;

    vehicleParent.wheelGroups[3].wheels = new Wheel[1];
    vehicleParent.wheelGroups[3].wheels[3] = suspensionRR.wheel;

    And same error.

    UPD:
    vehicleParent.wheelGroups = new WheelCheckGroup[4];
    vehicleParent.wheelGroups[0].wheels = new Wheel[1];
    vehicleParent.wheelGroups[0].wheels = GetComponentsInChildren<Wheel>();
    vehicleParent.wheelGroups[1].wheels = new Wheel[1];
    vehicleParent.wheelGroups[1].wheels = GetComponentsInChildren<Wheel>();
    vehicleParent.wheelGroups[2].wheels = new Wheel[1];
    vehicleParent.wheelGroups[2].wheels = GetComponentsInChildren<Wheel>();
    vehicleParent.wheelGroups[3].wheels = new Wheel[1];
    vehicleParent.wheelGroups[3].wheels = GetComponentsInChildren<Wheel>();
    And this still not working.
     
    Last edited: Jun 13, 2016
  32. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    GetComponentsInChildren gives you an array containing all instances of that script in the child objects. I meant that the VehicleParent's wheels array should be set with GetComponentsInChildren. Then use that array to set the wheel groups' wheels so that you don't have to use dedicated suspensionFL and suspensionRR type variables.
     
  33. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    I feel sorry for bothering you, but there is nothing I can do.
    First, I'm creating array of VehicleParent's wheels like this:
    vehicleParent.wheels = GetComponentsInChildren<Wheel>();
    Then, I'm creating WheelGroup array:
    vehicleParent.wheelGroups = new WheelCheckGroup[4];
    And then, I'm adding array of VP's wheels to WheelGroups wheels:
    vehicleParent.wheelGroups[0].wheels = vehicleParent.wheels;
    Still not working. I got an array of 4 WheelGroups, but keep getting error on setting wheels in groups.
     
  34. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    Ok, I decided to go ahead and write it in Unity myself, it turns out we were missing a new WheelCheckGroup declaration. This code should work no matter what script it's placed in. It automatically creates a wheel group for each wheel on the vehicle.
    Code (csharp):
    1.  
    2.   vehicleParent.wheels = vehicleParent.GetComponentsInChildren<Wheel>();
    3.   vehicleParent.wheelGroups = new WheelCheckGroup[vehicleParent.wheels.Length];
    4.   for (int i = 0; i < vehicleParent.wheelGroups.Length; i++)
    5.   {
    6.        vehicleParent.wheelGroups[i] = new WheelCheckGroup();
    7.        vehicleParent.wheelGroups[i].wheels = new Wheel[1];
    8.        vehicleParent.wheelGroups[i].wheels[0] = vehicleParent.wheels[i];
    9.   }
    10.  
     
  35. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Wow, I never would thought that I need to initialize it that way. It's working now.
    I can't thank you enough for your help.
    Edit: I forgot to mention one thing: after updating Randomation, there is one thing that was bothering me since then — sometimes cars behaviour becomes completely random, almost like gravitation is no longer here. Sometimes it happens after collision, sometimes it happens out of nowhere.
    Here are some screenshots:



     
    Last edited: Jun 17, 2016
    Meltdown likes this.
  36. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    You can probably fix this by lessening the hard contact force or hard contact sensitivity on the suspensions.
     
  37. Greg-Bassett

    Greg-Bassett

    Joined:
    Jul 28, 2009
    Posts:
    628
    I have just seen this on the Randomation website... :-(

    http://blog.randomationmedia.com/

    The Future of RVP 2.0
    RVP 2.0 will be taken down from the asset store by the end of the month and no more updates will be released afterwards. Support will cease at the end of 2016. 11-Jun-16

    Justin, why are you removing this incredible asset and stopping support of it?

    :-(
     
  38. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    My life is getting busier and I have less free time, and I don't want to spend that little bit of free time working on the asset and supporting it. Sales have dropped significantly this year and there is little financial reason to put time into developing it anymore. (I don't want to invest time into marketing either.) I know people are enjoying using it to make games, but I can't continue to support it under my circumstances.

    It wouldn't be fair to abandon new customers, so I'm taking the asset down very soon in order to stop acquiring new customers which will need to be supported. I will stop supporting it after 2016 is over so at least people who purchase it this month will still have 6 months of support.
     
  39. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    I have Contact force 50 and contact sensivity 2, and lowering both of them gives no result.
     
  40. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    Can you e-mail me the project so I can take a look? I can't think of what could be causing it off the top of my head.
     
  41. Justaway

    Justaway

    Joined:
    Feb 14, 2016
    Posts:
    11
    Sent you the project.
     
  42. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    @RandomationGames I'm having a strange issue with vehicle velocity on mobile. When I set the throttle on a desktop client, using throttle = Input.GetAxis("Accel"), All is good.

    However, on my Android device, I am using Input.GetTouch, to determine if I've pressed a button on my UI, and from there I'm calling VehicleParent.SetAccel(1.0f) if the button is pressed.

    But for some reason the vehicle on Android just ends up going ridiculously fast, i.e attains a much higher top speed than it does on desktop. I am also clamping the value to 1, as you have done in your Mobile Input example.

    Is there anything I could check that could be causing this?
     
  43. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    I really don't know what could be causing this, does it happen on every vehicle?
     
  44. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    How do you mean every vehicie? I only have one custom vehicle prefab that I use in my game.
    Perhaps I could send you a small repro project and you could check it out on Android?
     
  45. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    I thought your game had more vehicles, but yes you can send the project to me.
     
  46. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    hey,
    i just tried the motorcycle in my game and when i drop the motorcycle prefab in my scene, it somehow shakes weird all the time. see here: http://www.giphy.com/gifs/xT8qBticlZPCKjM5wY

    do you maybe know what cause this?
     
  47. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    The manual shows that the VehicleBalance script is unstable and I only included it in case some people want to mess with it. I haven't managed to achieve stable bike physics, that's why I never advertised the package as supporting bike physics despite including a bike prefab. Unfortunately I still don't have a way to improve it.
     
    Der_Kevin likes this.
  48. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    Hey, what happened? I cant find RVP on the asset store.
     
  49. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
     
  50. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    375
    The asset store desperately needs a way to send newsletters or mass-messages to all customers. The only way I can make announcements is through my website and the forum; hoping that important information trickles to the customers as they stumble across it.