Search Unity

Randomation Vehicle Physics 2.0 - Now open source on GitHub!

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

  1. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    I just tested the RWD car prefab with increasing the brake force to 1 on all wheels and it slowed down fine. If the wheels are not spinning and the car is still sliding then you should try adjusting the friction settings on the tires. The brake only controls how much the rotation of the wheel is slowed down, it's the tire's job to actually grip the ground and slow the vehicle down. The forward friction curve is probably what's causing this, with the rightmost keys after the peak of the curve indicating the friction while sliding.
     
    Meltdown likes this.
  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    I get what you're saying, and I'll try adjust those things. But it still seems weird the tyres can grip the surface perfectly fine when spinning forward, but not grip when they are stopped.
     
  3. jackcrosa

    jackcrosa

    Joined:
    Oct 16, 2012
    Posts:
    22
    How can I rig the car ? ( add a new car)
     
  4. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Have you read the section of the manual titled "Setting Up a Vehicle"? Duplicate the prefab most similar to the vehicle you want to make, swap out the meshes for your own, then customize the engine, transmission, suspensions, and wheels as needed. I'm working on new features to make the process easier.
     
  5. jackcrosa

    jackcrosa

    Joined:
    Oct 16, 2012
    Posts:
    22
    I am having problems with playing a car using irds system , car keeps crashing .
     
  6. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Is it because the car's physical properties are making it unstable, or is it because iRDS is guiding it into crashes? If iRDS is causing the crash, you may want to post in the thread for that.
     
  7. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    hey! iam somehow having problems setting up my car. Iam using the "short Car" prefab as a base and copied the values from there.
    the wheels are making some trouble shomehow:


    so the front left and rear right wheel in the above screenshot are rotated wrong as you can see. but the gizmos are pointing in the right directions. with the rear left its the opposite as you can see.
    how can i set it up that both is working? when i just place my model the wheels are correct

    edit:
    nevermind, i just used the short car and replaced the meshes. that was easier :D
    but i have another question. in the short car you have 4 colliders: midcollider, frontcolldider, rearcollider and undercollider. what is it good for? why not just have 1 collider with the dimensions if the whole body?
     
    Last edited: Oct 9, 2015
  8. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Edit: The update still isn't ready, but some optimizations have been successfully implemented including compatibility with greater fixed timesteps and being able to distribute wheel raycasts across multiple frames. You can e-mail me with your invoice number to get the updated scripts if you can't wait until the update is officially released.

    Because one convex mesh collider alone will fill in the area between the hood and windshield, and the area between the rear window and the trunk. You can have it this way if you want. The underside collider is mainly for having reduced friction on the underside and not detecting crashes when landing on things. Colliders with the "Underside" tag won't register crashing collisions from the VehicleParent script. The VehicleDamage script overrides this if it is attached.
     
    Last edited: Oct 9, 2015
  9. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    aahh, yeah. that makes perfects sense, thanks for clearing that up :)
    i have one more question, do you have a recommendation how to do splitscreen/local multiplayer? maybe an asset or starting point?
     
  10. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    The main hurdles with splitscreen implementation include:
    • Setting up an input manager class to work with multiple controllers.
    • Reducing draw calls to an acceptable amount.
    • Getting audio to work well with one audio listener.
    Unity can be finicky with more than one gamepad hooked up. In the past I've used XInputDotNet and it worked well. (For XInput controllers, at least.)

    You also have to make sure to scale the FOV properly with the aspect ratios of the camera views, since they will change with two-player split screen, getting either wider or taller depending on the split.

    I don't have as much experience with the audio, but for the players other than P1, you could transform their child audio sources to be relative to the audio listener's local space based on their relative position to the players' individual cameras.

    You can download the source to my abandoned kart racer project as an example, but the code is messy and written in JS. It only works with Unity 4.6.
     
  11. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Just another demo of what I want my game to be like - I'm thinking of making it less abstract-like and making it look reasonably real. I might throw in things like hill climbing, drifting etc. Tell me your thoughts and how I can improve!


    Also, if any of you (for some reason) want a two sided standard shader (for if you use detachable parts and you can only see one side of your models), then here you go!
    Get it here (Standard (Two Sided).shader)
     
    JustInvoke likes this.
  12. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    hey, wow, thats something i can work with - thank you verry much! you should finish the game. it looks great! :)
    i guess i will start with a multitrack cam so i dont have to care to much about drawcalls and sound :)
     
  13. Deleted User

    Deleted User

    Guest

    Is there a option, how to synchronize the damaged vehicle?(over network)
    It seems, that i can't damage the vehicle when im not driving it.

    I synchronize the transform, rpm and the steer angle.
     
  14. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Not currently, but in the future I want to refactor the damage to have an ApplyDamage() function that isn't limited to collisions. It won't be in the next update, which I plan on submitting either today or tomorrow.
     
  15. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    I'm nearly to buy it.
    But before this, i have some questions.

    1. How easy is it to implement the stunt detection for ai? With points ;)

    2. It is any mobile optimations planned?
    Sometimes i have 30 fps with 4 cars and sometimes 16fps with only my car.
     
  16. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    1. There is a StuntDetect script that can be attached to any vehicle with a public score variable you can get the score from. There is currently no AI implemented that will automatically perform stunts.

    2. Version 2.07 was recently submitted for review containing some optimizations. You will be able to set the fixed timestep length to be greater than 0.01 and configure wheel groups for distributing raycasts across multiple frames. There will be a new mobile demo released with better performance once the update is live.
     
    Neo-Gamefactory likes this.
  17. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    Thank you :)
    You got me :)
     
  18. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Version 2.07 has been released with the following changes:

    The changelog is now in a separate document.

    Support for variable fixed timesteps.

    Disallowed multiple instances of certain components on same object.

    Added component menus for all MonoBehaviours.

    Motor and Transmission classes are abstract in C#.

    New TerrainSurface script for configuring ground surfaces on terrains.

    The wheels array on the Wheeled Tank prefab now contains all of its wheels.

    F – New static GetTopMostParentComponent() function for getting the topmost parent of a transform with a certain component. Vehicles can now be children of other objects during Awake() and Start().

    VehicleParent – New WheelCheckGroup class.

    New “wheel groups” array for distributing wheel raycasts across multiple fixed steps.

    New “Get Engine” and “Get Wheel” inspector buttons.

    VehicleDamage – “Collision ignore height” gizmo is now drawn with correct local rotation.

    HoverWheel – Improved hovering force with new “buffer distance” and “buffer float force” variables.

    Improved braking force.

    Changes to work with VehicleParent's wheel groups.

    Used GetTopmostParentComponent() function.

    New “Get Visual Wheel” inspector button.

    HoverSteer – Used GetTopmostParentComponent() function.

    HoverMotor – New “Get Wheels” inspector button.

    GroundSurfaceMasterGroundSurface class now has “name” variable. Set this to work with new inspectors on GroundSurfaceInstance and TerrainSurface.

    GroundSurfaceInstance – Surface types can be identified by their name.

    TimeMaster – New static “fixedTimeFactor” variable for working with variable fixed timesteps.

    New static “inverseTimeFactor” variable, equals 1 / fixedTimeFactor.

    GlobalControl – Time.fixedDeltaTime is reset to initial value with quick restart.

    DetachablePart – Used GetTopmostParentComponent() function.

    Handles for moving and rotating hinge anchors and axes of part joints.

    FollowAI – Used GetTopmostParentComponent() function.

    Motor – Used GetTopmostParentComponent() function.

    Estimated vehicle top speed is displayed at top of inspector.

    Boost burn rate is independent of fixed time.

    SteeringControl – Steering rate is independent of fixed time.

    Used GetTopmostParentComponent() function.

    Suspension – Hard contact force works properly with different fixed timesteps.

    Used GetTopmostParentComponent() function.

    Checks if wheel exists before drawing gizmos.

    New “Get Wheel” and “Get Opposite Wheel” inspector buttons.

    SuspensionPart – Handles for moving the connect point.

    TireScreech – Used GetTopmostParentComponent() function.

    TireMarkCreate –Removed private curSurfaceInstance variable as it seemed redundant since the wheel's contact point already contains surface type info.

    Fixed issue where tire marks would be left instead of rim marks if tires were popped while skidding.

    Transmission – Used GetTopmostParentComponent() function.

    ContinuousTransmission – Improved automatic shifting and proper ratio multiplication with feedback RPM, fixed issue where ratios didn't change top speed.

    GearboxTransmission – Changes to work with variable fixed timesteps.

    New “Calculate RPM Ranges” inspector button.

    Refactored CalculateRpmRanges() function.

    Wheel – Used GetTopmostParentComponent() function.

    Changes to detect TerrainSurface dynamic friction.

    Changes to work with VehicleParent's wheel groups.

    Air leak rate works with different fixed timesteps.

    New GetWheelDimensions() function for getting the dimensions of the rim/tire meshes.

    New “Get Wheel Dimensions” inspector button.

    MobileInputGet – New “use accelerometer” variable.

    VehicleAssist – “Angular drag on jump” timer works with variable fixed timesteps.

    VehicleBalance – Smooth leaning works with variable fixed timesteps.

    PropertyToggleSetter – New “Get Variables” inspector button.

    CameraControl – Changes to work with variable fixed timesteps.

    StuntDetect – Changes to work with variable fixed timesteps.
     
  19. DesertEagle

    DesertEagle

    Joined:
    Dec 29, 2013
    Posts:
    5
    Hello. First - thank you for really impressive asset. Now to the question:
    When you are dealing with cameras in your CameraControl, you are using "norm" object , and, as wiki says, it's transform.up corresponds to normalAverage (so basically vehicle local "up"). But in the script you are using norm.up vector as vehicle "forward" vector and norm.forward as vehicle "up" vector (so basically other way around). What does that mean?
     
  20. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Edit: I've just realized the engine variable of the VehicleParent script isn't shown in the manual, I've updated the manual on my site with the proper info.

    Edit 2: I also realized that some of the scripts throw errors when added to objects because some of the new editor scripts are checking for the length of arrays, and when adding a new script to an object, the arrays are null at first. I will be submitting a fix very soon.

    Are you looking at the wiki for the old version of the package (1.5)? This is the manual for this version, a PDF is included in the project folder as well.

    There is still a norm object in this version, but it's not mentioned in the manual. You can see where its rotation is set in the VehicleParent script at line 226 in the latest version. The reason why its rotation is set like that is because of the nature of the Quaternion.LookRotation function, where the forward vector overrides the up vector such that the up vector is forced to be orthogonal to the forward vector. The average surface normal of the wheel contacts is the more important vector.
     
    Last edited: Oct 22, 2015
  21. DesertEagle

    DesertEagle

    Joined:
    Dec 29, 2013
    Posts:
    5
    Thank you for the answer.
    I saw info about norm object here: http://randomation-vehicle-physics.wikia.com/wiki/VehicleParent. Maybe it is indeed of some old version.
    Another question is about engine properties (rpm, to be precise): as I can understand. the engine rpm is now meant to be obtained via ((GasMotor) vehicleParent.engine).transmission.outputDrives[0].rpm right? Or is there a more simple way?
    And I have checked this value and it appears to go down to pretty much zero when I realease acceleration button. I think rpm should gradually decrease, shouldn't it?
     
  22. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    That wiki is for the old version.

    Each part of the drivetrain has a DriveForce script attached with variables like torque and RPM. For the engine RPM you want the feedbackRPM variable of the attached DriveForce script, as it represents the final RPM of the engine considering the speed the vehicle is driving at.

    The RPM variable is what the engine wants to drive at, which is why it immediately goes to zero when the throttle is released.
     
  23. DesertEagle

    DesertEagle

    Joined:
    Dec 29, 2013
    Posts:
    5
    Yes, but value of a feedbackRPM is unique to each drive force. I've measured feedbackRPM while driving on 2 wheels only, and that were the results: 1073.359, 3981.972, 1056.61, 3353.192. So it looks like it is not rpm of an engine, but rpm of a wheel (otherwise how one engine can have 4 different rpms at a time?). How do I get engine rpm from these 4 values?
     
  24. phimo

    phimo

    Joined:
    Aug 7, 2012
    Posts:
    9
    Hi there,

    Higher fixed timesteps than 0.01 makes the car jitter, even with the example cars (at least starting at 0.02)

    Is there any way to remove this jitter or is this because of PhysX? I already tried to add interpolation to the rigidbodies and changed the camera to work with a rigidbody and forces to follow the car interpolated. The car still jitters when accelerating when standing and also a little while driving.

    I previously used EVP and there it wasnt that big of a problem to raise the timestep to ~0.03.

    On mobile with mesh colliders for a mesh terrain and mesh collider for the street the performance is not that good. At least on low/mid range devices like the Galaxy S4.

    At least I was able to increase the timestep to 0.02 without that much of jitter (a little bit still remains but it seems playable)

    Looking forward for your answer
    Best regards
     
  25. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    Hey just checked out the new update and it's great! Your version of handling terrain texture detection is much better than mine! Very simple and accurate. Thanks for continuing to update this awesome asset and all of the quality support you provide!
     
  26. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    Check out Rewired from the asset store. It's by far the best solution for handling controllers that I've found. Unity should seriously consider just buying it from the guy and implementing it as a core component. It handles every type of controller I've plugged into it, multiple controllers, hot plug-n-play, etc. Worth every penny.
     
  27. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    You just need to pay attention to the DriveForce on the engine itself. The feedback RPM variable starts at the wheels and goes backwards up the drivetrain. For parts with multiple output drives, they get the average feedback RPM of all of them. With transmissions, the feedback RPM is affected by the ratios as well.
    The jitter is because of the relationship between the forward slip and sideways slip of the tires. You can see that the jitter is most noticeable when accelerating or braking, this is because the forward slip is increasing, which affects the sideways slip based on the slip dependence variable on the wheels. If you set this to "Independent" the jitter is much less noticeable, but then you can't drift by holding the ebrake because the forward slip isn't causing the wheels to lose sideways friction. I'm going to work on some new options for adjusting this.
     
  28. phimo

    phimo

    Joined:
    Aug 7, 2012
    Posts:
    9
    Thanks for your response!
    I'm using a 0.015s Timestep now. The jitter is barely noticeable on a mobile device and the performance is OK with 4 cars. Especially with the new wheel groups for AI drivers. This saved some precious performance.

    Looking forward for the next awesome updates.

    Great asset btw!
     
  29. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Version 2.07.1 has been released with some small fixes to errors that would appear if the following scripts were added to objects:

    TerrainSurface – Would throw error if no terrain data was assigned.

    GasMotor – Because of null array check in editor script.

    HoverMotor – Because of null array check in editor script.

    DetachablePart – Because of null array check in editor script.
     
  30. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    I've successfully built a working multiplayer server with RVP 2.07.1 using uNet.

    The only issue I've had is getting the steering to sync.

    The client/host sees it's own wheels turn, but not other players.

    I've also got the game running on my server so clients from different platforms can join one server. Example: I can join a game that's running through a browser on a standalone executable.
     
    Last edited: Oct 28, 2015
  31. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    Hmm is there any tutorial to set up a complete Vehicle without a template?
     
  32. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    In the SteeringControl script there is a private variable named steerAmount representing how much the wheels are steered. This is automatically set based on the steerInput variable of the VehicleParent script, but maybe it could be modified so that it's based on steering values sent over the network.

    No, but you could still have one of the template vehicles sitting in the scene as a reference when building your own, so you can see what components each object needs to have. You can also take a look at the "Child Objects" section of the manual, describing the purpose of the child objects inside a vehicle.
     
  33. Deleted User

    Deleted User

    Guest

    To synch the steering, im using the input from the player and of course the brake input for the brake/reverse lightning. To let the wheels rotate correctly, i just use the currentRPM from the Wheel[] of the vehicleParent.

    This works perfect for me, but i can't synchronize the damage, i hope that, there will be some updates, where it would let my synch the damage.
     
  34. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Hmm I get what you're talking about. Could you please show some screenshots of this from in the editor?
    Cheers
     
  35. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    With a custom window with all Settings it will be much easier ;)
    So i must go to this script, that is attached to this gameobject, then to this with this... and so on.
    it is a little bit confusing me ;) and hard to understand
     
  36. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    I will try to refactor the damage so that it can be applied with a function call and not just collisions.
    The modular setup of vehicles makes it difficult to design an editor window for building them, I'm not sure at the moment how I will improve this aspect. Is there any particular reason you don't want to use the templates?
     
  37. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    @RandomationGames is there a preferred way you would use to sync the steering over uNet?
     
  38. iamspugeddy

    iamspugeddy

    Joined:
    Oct 8, 2015
    Posts:
    6
    Are there any tutorials on how to map the suspension and wheel colliders to custom vehicles? Adding the wheel scripts to wheels forces them to spawn directly underneath the car, turned at a 90 angle, and stretched. I'm fairly new to Unity so maybe I'm missing something really basic. But any help would be great. Really great asset, look forward to future releases.
     

    Attached Files:

  39. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    You can probably just sync the steering input, it's hard to say since I'm not experienced with networked games.
    There isn't a tutorial, but the wheels should be rotated so that their local forward direction points out from the side of the vehicle, or the face of the rim. You may have to adjust this in your modeling application. If the wheel is appearing stretched out like that when you click the "Get Wheel Dimensions" button, then there is a problem with the rim/tire mesh since it's based on the local positions of the vertices.

    Based on the position of the cylinder gizmos, it looks as if the wheel object is at the center of the vehicle. It needs to be where the actual wheel sits.
     
  40. DesertEagle

    DesertEagle

    Joined:
    Dec 29, 2013
    Posts:
    5
    Thank you!
    Here is another question:
    I am trying to simulate engine stall, but when I set ignition to false manually RPM on the engine just freezes at vehicle keeps driving forever. How to use ignition properly?
     
  41. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    By default there is no friction in the drivetrain, so vehicles will roll forever unless the brakes are applied or a collision occurs. Try increasing the axle friction variable on the wheels to make vehicles roll to a stop slowly.

    There is also no smooth transition between the off and on states of the engine, so the audio will immediately cut out if ignition is disabled. I might add a smooth ignition sequence in the future, but it's a low priority feature.

    Edit: The HUD's RPM meter is based on the target pitch of the engine sound. This isn't set to change when the ignition is disabled, so it appears to remain the same after it's turned off. I'll address this in the next update.
     
  42. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    I use the Templates, but it is hard to understand ;)
     
    Der_Kevin likes this.
  43. DesertEagle

    DesertEagle

    Joined:
    Dec 29, 2013
    Posts:
    5
    Thank you, that worked, but partially, because player can still control acceleration and drive around, althought slower. It maybe due to the fact that when ingnition is turned off manually, rpm value freezes (as I have mentioned) and a completely stationary car can have like 6000 rpm. Even if collision occures. This value recalculates only when ignition is on.

    But I don't use it, I display feedbackRPM variable of an engine through GUI.Label.

    For now I am achieving target effect by killing the engine (health = 0). This prevents user from using acceleration.

    EDIT: Also, when I start with ignition = false, there is exception spam about targetDrive.curve is null on GearboxTransmission:87. (I use MuscleCar for tests)
     
    Last edited: Oct 31, 2015
  44. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Regards about the networking. I'm having a few issues on the car not syncing the rotation properly. Anyone have some values that work?
     
  45. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    I've made some changes to the Motor and GasMotor scripts to fix the problems you're having, if you e-mail me with your invoice number I can supply them. For everyone else, these will be available in the next update.
     
  46. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    Maybe I found an issue...

    I start my game on Android, 60fps, make a crash and lead level again to reset everything.
    After 2 crashes with level load(reset) fps drops to 8. in your Android demo is it the same.

    Some problem with garbage collection or so?
    I will test around with some settings, I just want to say this issue ;)
     
  47. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    376
    Does it stay at 8 fps indefinitely, or just for a few seconds? Reloading levels is taxing since everything has to be destroyed and created again. Would it be possible for you to just reset the position of the vehicle and call the Repair() function on the VehicleDamage script rather than reloading everything?
     
  48. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    This was also my Idea to test ;)
    This works, perfect. But i don't understand why it drop the frames after reloading but only after few crahses. If no crash and reload it is still 60fps and more.

    Hmm, than it is a Unity thing ;) Thank you for help :)
     
  49. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Okay so with my multiplayer game, whenever a client (or host) presses R, X or Z, the session crashes and everyone gets booted off. So far I've disabled the quick reset on the GlobalControl script, but I can't find out which component the rotation and position reset are in
     
  50. Deleted User

    Deleted User

    Guest

    If i remember correctly it was the Debug Script, its attached on the vehicle.