Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Assets NWH Vehicle Physics

Discussion in 'Works In Progress' started by NWHCoding, Nov 30, 2017.

?

Which networking solution do you want to see implemented?

Poll closed Jan 20, 2019.
  1. UNet - Unity Networking, getting deprecated sometime in the future

    1 vote(s)
    4.8%
  2. Mirror - Community replacement for UNet (https://github.com/vis2k/Mirror)

    6 vote(s)
    28.6%
  3. Photon

    12 vote(s)
    57.1%
  4. None - I will be implementing my own solution

    2 vote(s)
    9.5%
  1. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,535
    Looking forward to NV2, though 2 of my requests are mirror networking and motorcycle support... mmmm :) at good cough low price if its going to be addon
     
  2. mthawley

    mthawley

    Joined:
    Sep 7, 2018
    Posts:
    62
    Will Version 2 be compatible with new Input System?
     
  3. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Goal is to have it compatible with old, new and Rewired.
     
  4. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Currently working on better trailer mechanics. The goal was to be able to attach a trailer to a trailer - among other things like moving the trailer code to a module and allowing for powered trailers.

    upload_2019-10-23_20-1-11.png
     
    Last edited: Oct 23, 2019
  5. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,535
    and yet I'd rather see mirror support built in, and it being easier to do motorbikes ... than... trailers ..it just seems so ...niche? anyway just my thoughts :)
     
  6. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Do not worry, both are on the way. You would be surprised as for how popular the trailers and articulated equipment are.
    I am first going through all the features that were in NVP1 and working on improving them, checking the code, etc.
    After that is solid comes new stuff.

    One of those things I have been working on is user-friendly inspector which evolved a bit further from the last update:

    upload_2019-10-24_12-43-39.png

    upload_2019-10-24_12-44-10.png

    upload_2019-10-24_12-44-40.png
     
    krou, GLID3R82, Player7 and 2 others like this.
  7. Janoooba

    Janoooba

    Joined:
    Feb 9, 2016
    Posts:
    37
    That looks fantastic! I'm super excited.

    Also. Excuse me if this has already been asked/answered, but is V2 a paid upgrade? And do we have a ballpark release estimate?
     
    digiross likes this.
  8. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,041
    Looks good.

    Q: How do you get the performance characteristics of a car?

    I need to know what the maxspeed is, for example.
     
  9. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    V2 will be a free upgrade BUT the additional modules will be provided at a charge.
    All the functionality from V1 will be included in V2 except for the tank mechanics which will be a $10 extra - so if you are using that it will be a paid upgrade in a way. Still, those ten dollars will justify me spending more time working on specialized vehicles which most of the customers do need which will result in better modules, and yet will keep the price of the base asset the same.

    Ballpark release date is as soon as it is finished - current state is that the base stuff is done and I am from today starting work on actual improvements and new features. End of year is a hard limit, one month is very optimistic limit. Somewhere in between lays the answer.
     
    GLID3R82 and krou like this.
  10. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,041
    Is it possible to find the pitch and yaw of the vehicle?
     
  11. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Yep, and you do not need any asset to do that and this is not specific to any asset.
    There is no such helper function built into NWH Vehicle Physics but you could always do something like this:
    https://forum.unity.com/threads/roll-pitch-and-yaw-from-quaternion.63498/
    In short - convert rotation to local and compare that to your frame of reference [0,0,0].
     
  12. thrandur

    thrandur

    Joined:
    Feb 6, 2019
    Posts:
    3
    Any hints on how I would control speed, steering and other things from code (automatic driving)?

    Also some pointers on how to make my own models similar to the cool monster truck - using Blender - or is it better to find something in the asset store?
     
  13. thrandur

    thrandur

    Joined:
    Feb 6, 2019
    Posts:
    3
    Found out how to control these things by looking at the demo project :)

    Procedure:

    Add this on top:
    using NWH.VehiclePhysics;

    Declare:
    private VehicleController vehicleController;

    Define in start:
    vehicleController = GetComponent<VehicleController>();

    And then you can change things:
    vehicleController.input.Horizontal = 0f; //straight ahead
    vehicleController.input.Vertical = 10f; //engine forwards
     
    Janoooba likes this.
  14. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    This is correct and sorry for not replying earlier.
    There is an explanation on how the input system works inside the manual but in short the point is that the input is set externally, so you can do things such as above. DesktopInputManager works in the same way and writing your own input manager is therefore very simple - only a few lines.

    One not tho: setting the value of Vertical to 10f will do nothing since all the float values are normalized (in this case to [-1, 1]). Just set it to one.
     
  15. thrandur

    thrandur

    Joined:
    Feb 6, 2019
    Posts:
    3
    No problem - so +1 is full throttle and -1 is backwards full throttle :)

    Do you have hints for my second question:
    Some pointers on how to make my own models similar to the cool monster truck - using Blender - or is it better to find something in the asset store?
     
  16. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    I would suggest searching for rigged/animated models - unfortunately there are not many so the best bet would probably be rolling your own. Tutorials on working with bones in blender will be of use, even better are ones that show you how to make bones work with Unity because Blender being blender it is not that straightforward.
     
  17. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    After spending good part of the week reworking the solver for NVP2 I have finally come up with a result that gives the same accuracy as the tech demo build from two months ago but with a fraction of performance cost. In fact - the new physics calculations are faster than the ones in NVP1 while being a lot more realistic.

    In-build profiler - note that the time is for two calls of FixedUpdate() and that WheelController is now being called from the vehicle script itself so the whole vehicle is using 0.04ms per fixed update:
    upload_2019-11-8_22-0-35.png

    Even in editor this time is around ~0.1ms per fixed update. Need to do some testing of the new (3rd) solver but so far seems very promising.
    Note that this is before any optimization :D
     
    Last edited: Nov 8, 2019
    GLID3R82, krou, xDeveloper and 4 others like this.
  18. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    690
    Hi, while we are talking about performance, I was curious if you are going to take advantage of Burst Compiler.
    It can increase the performance several times depends on the usage but I'm pretty sure NVP will get pretty good benefits.
    Please let us know if you are going to do support it soon, hopefully before v2. I think we'll have then, the most sophisticated Vehicle engine with the fastest performance.

     
  19. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    I am using Burst compiler with Unity Jobs system in Dynamic Water Physics asset. I have explained here before why I will not use it here. Sure - if you are planning to run 50 cars on a racetrack then sure - you would get <5% performance increase. Running one car you would actually get performance decrease due to the jobs not being free and needing to be set up, data copied to native arrays, etc. Thing is that out of total performance hit of a vehicle, only small percentage is the solver. Sounds, exhausts, wheels, effects, etc. take up much more. And since solver is not stateless you can not just put each iteration on one thread and call it a day, they need to be executed one after the other.
    With Dynamic Water Physics it makes sense since all the simulated points are individual and I have made it so all the data is stored in one place - one large array. There can be two or more thousand points and processing those can be nicely spread among threads. Here not so much.
     
  20. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    690
    Hmm.. <5% performance gain from using both jobs and Burst compile is somewhat surprising if you are using 1000s of points for buoyancy testing.
    Are you sure you turned on the Burst compiler? not just using Jobs? Jobs can run in parallel and I think you will gain some performance boots just from using Jobs alone. And Burst can also add quite a bit of boost on top of that.
    It seems bizarre and there must be something wrong. I would suggest you talk to Unity guy and see there is something obvious problems.

    And regarding NVP, I thought jobifying wheel raycast would get some performance boosts not others.
    But only the real test will show the true results.
     
  21. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Oh, you misunderstood me. I was talking about possible performance gain in NVP2. There is a huge performance gain inside Dynamic Water Physics 2.

    Also, WheelController3D already uses jobs for raycasts.
     
  22. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    690
    I see.. that's good to know. I'll be looking forward to the new version. Thanks.
     
  23. admin_unity486

    admin_unity486

    Joined:
    Oct 16, 2019
    Posts:
    5
    hey guys i was wondering how i can change the sound of the cars ?
     
  24. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    690
    Oh, btw, I noticed you are supporting PUN, and not Mirror.
    Mirror is more like the standard Unity networking framework, in my opinion, inheriting UNET legacy. I've waited for the new Unity Network Stack for a year and it will probably take another year or two until it becomes usable. Besides, you will need to convert your game into ECS in order to use it. It will limit to very few people who can take advantage of it.

    It will be really nice if you can support Mirror. Is this something you will consider?
    If not, how shall we go about syncronizing vehicles over the network?
    I think there two different kinds of approaches.

    1. Syncronize just basic vehicle parameters and simulations are done on all participating clients. This will give better looking vehicle physics but it will probably not scale in terms of performance.

    2. Each client will simulate the vehicle he is driving and send the final result such as vehicle, wheel positions. Simulations are spread over several clients and it will not be taxing on performance but syncronizing simulation quality will be determined by network quality, i.e. wheels may not contact the ground at all time.

    From what I gather, simulating every vehicle on each client will take too much CPU cycle and I would like to take #2 approach at first but you may have different opinions. If simulating 10 vehicles takes less than 5 ms, #1 approach may be possible but I'm not certain if I can keep them under 5ms.

    What kind of approach did you take for PUN and what are the results?

    Thanks.
     
    NWHCoding likes this.
  25. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    As mentioned a few posts above Mirror in on the way with NVP2. Also, current implementation of PUN does exactly that.
    Clients only run vehicle physics on their own vehicle and only the results are carried over (position, rotation, steering angle, etc.).
     
  26. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    There is a 'Sound' dropdown and you will see a few different sounds such as 'Engine Idle' (which will be changed to Engine Running in the future to avoid confusion), 'Engine Start Stop', etc. Here are all the settings for all the sound, including volume, pitch, etc.
     
    admin_unity486 likes this.
  27. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    690
    Oh, I only saw some requests and indeed, it's really great news! And I really like you are sending the simulation result over the network. No need to worry about high CPU usage. ^^

    In the meantime, I'll study how you implemented PUN.

    I read ETA V2 for about a month. I assume that it will come with Mirror integration.
    Please let me know if I'm not correct.

    Thanks.
     
    Last edited: Nov 13, 2019
    NWHCoding likes this.
  28. admin_unity486

    admin_unity486

    Joined:
    Oct 16, 2019
    Posts:
    5
    thank you i missed it yesterday and now feel like an idiot ahah
    also imm having trouble getting damage to work when i import my own car ? says its enabled
     
  29. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    A quick update on the progress:
    Powertrain is mostly done. Solver works nicely, results are physically accurate and I have tested a lot of scenarios and they all seem to work exactly as they should. Currently working on resolving a slight shudder at very low transmission ratios (not really a bug but more of a side-product of running solver at much higher frequency than fixed update) - but then 1:100 ratio is quite extreme and actually works very well and will make for great tanks and semis.

    Next come optimization, minor improvements and general checks on the powertrain and then I will wrap that section up.
    Next come general improvements, Mirror support, etc.
    So the update is progressing well, although I spent almost two weeks (re)working the powertrain/solver which did set back the release some. But I think the time was well worth it in the end. Will post a small development build in a few days so you can judge for yourselves.
     
  30. RichardSim

    RichardSim

    Joined:
    Dec 15, 2013
    Posts:
    14
    I'm looking at starting a new project, and I'm curious what you think the transition from NVP1 to NVP2 will look like? i.e. should I hold off investing too much time on the vehicle-side of the project to make the upgrade easier/possible, or is it likely to be pretty painless?

    I'm looking forward to seeing the updated dev build soon!
     
  31. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Due to the amount of changes setting up a vehicle from scratch will be needed. Some things - such as wheels, will not be changed much but the vehicle inspector itself is different and it will not be possible to just copy over the values. Still, the basics will stay the same (engine power is still engine power, gear ratios, etc.) so it will not be complete new setup from the standpoint of tuning the behavior of the vehicle, just the settings that will need to be transferred.
     
    krou, RichardSim and GLID3R82 like this.
  32. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,041
    Can you do direct drive single gear electric vehicles with NHW?
     
  33. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    I have not tested it in NVP1 but in theory yes. Use a single gear on the gearbox (single forward, single reverse, automatic sequential) and mostly flat power curve (I would recommend not setting it to full power from 0 tho).
    Replace the Engine Idle sound with the motor whine and you should be good to go.
     
  34. Anhella

    Anhella

    Joined:
    Nov 18, 2013
    Posts:
    46
    good day
    when I go to get in the car the car rolls away from me can anyone tell me how to fix?
    I am using third person cover shooter I bought from the asset store.
    thanks in advance
     
  35. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Try ticking "Freeze When Still" option under General Settings foldout (towards the bottom of vehicle controller inspector).
     
  36. Anhella

    Anhella

    Joined:
    Nov 18, 2013
    Posts:
    46
    good day
    the car still roll over when trying to enter and even if I get close it still wont allow the player to enter the car when I press V. do you have any other solution.
     
  37. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    Hello, please check your email. The issue you are having with V in builds is because you have not assigned the button for VehicleEnterExit in Project Settings > Input. Also check the Input section in manual.
    The flip over could be that your vehicle is detecting the player as a surface (esp. if wheels are peeking outside the vehicle body collider). Try assigning the player's layer to ignore layers list of WheelController.
     
  38. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    314
    Hi,

    I was bought NWH Vehicle Physics, and can i update to v2 for free ?
    And any chance for physics support rally car ?
     
  39. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    V2 is not out yet but yes, it will be a free update despite having spent a lot of time on it. The only thing that will be paid compared to V1 is different modules: tanks, motorcycles, etc. which will allow me to spend more time developing said modules which will ultimately result in better quality, while still maintaining the price of the base asset for those that do not need the extra functionality.
     
  40. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    I would like some input on LOD system that will possibly be integrated. The idea is to have a selector above each vehicle component (e.g. sound, skidmarks, etc.), just where the Enabled/Disabled button is in previous screenshots, that would have following options:
    • Always Enabled
    • LOD0
    • LOD1
    • LOD2
    • Always Disabled
    Where LOD 1, 2 and 3 have configurable distance.
    This would replace current binary button (Enabled/Disabled) and allow for automatic LOD management. E.g. as the vehicle approaches first you would enable lights, then sound, then skidmarks and exhaust smoke as it gets nearer.

    What do you think about this idea? Would it be useful?
     
    GLID3R82 and Rotary-Heart like this.
  41. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    690
    Sure, It sounds really useful. Would the number of raycast(or whatever that will make the simulation cheap) be configurable? For making such as NPC cars, simplified vehicles would be useful to have as much as cars on the street. Right now, I'm using NWHVehicle for drivable car and other vehicle controllers for NPC cars and I would like to keep just one.
    Thanks.
     
    NWHCoding likes this.
  42. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    The LOD system is all done and this is how it works:

    upload_2019-12-2_20-39-50.png

    The title bar for each component has a few options. On the left you can see 0, 1, 2 and 3 buttons. Those are LODs that have been setup under vehicle settings (number of LODs is not limited - except for GUI space). Each LOD has a distance setting and when distance from vehicle to camera is greater than the distance of that LOD entry, the component is disabled. In the image above LOD system is not being used and instead the component is set to 'Enabled' manually (green button).

    When one of the LOD buttons is clicked this is what happens (e.g. click 1):

    upload_2019-12-2_20-39-35.png

    Now the 'Enabled' button is hidden and vehicle decides when to enable the component based on distance from player.
    Colors show at which LODs the component (Sound in this case) will be enabled (green) and at which it will be disabled (red). In this case Sound will be enabled at LOD0 and LOD1, while it will be disabled at LOD2 and LOD3. Clicking on currently active LOD button (1 in this case) disables the LOD system for that component and the title bar goes back to image 1.

    This is way clearer once you see it in action and hopefully quite intuitive.
    TLDR; you can manually enable/disable individual components or let the LOD system do that for you based on distance.

    The "S" (Sleep) option has been removed and will be completely replaced by the LOD system. Instead, sleep will lock vehicle into using one of the LODs (say 3 in this case). This means that while sleeping it will be forced to use that LOD no matter the distance from player. This is useful for vehicles that need to be near to the player but do not need all the functionality (e.g. NVP1 demo had multiple vehicles but only one active at the time while the rest were sleeping).

    As for the update on the progress of the asset I am slowly entering the polishing stage. There are still features to be implemented waiting on the TODO list but that list is getting shorter by the day. The gnarly things such as the physics are done and the rest should progress much faster.
     
    Last edited: Dec 2, 2019
    GLID3R82, chrisk and Rotary-Heart like this.
  43. RichardSim

    RichardSim

    Joined:
    Dec 15, 2013
    Posts:
    14
    That LOD system looks great - very easy to use and clear.

    Something I'm always concerned with for LOD systems is popping, and graceful fallbacks. Is there a way to have a script receive events about LOD changes, so that it can handle whatever fallbacks are necessary as the LOD changes? Or even better, let the components be overridable (or an interface or fascade used so the script can call down to the actual system as necessary).

    I'm thinking it would be good for things like having gradual degredation of LODs (e.g. lights go from 2 to 1 to 0, exhaust emission rate tapers off smoothly, etc). Such functionality would also allow you to do specific things even if the component is disabled due to LOD - say if I wanted to keep track of surface wear/degredation where skids are happening, even if the skids won't be calculated/rendered because they're far away.
     
  44. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    I do not think that I will go deeper into LODs at the moment or I will just complicate things and move the release date even further.

    On the completely unrelated note, V2 will have positional audio:
    upload_2019-12-3_19-52-36.png

    Days of having bus engine sound come from the center of it are over. Same with other large vehicles or vehicles with engines in non-central locations.

    I am currently working on effects and sound so if you have any ideas or suggestions you would see implemented do tell.
     
    Last edited: Dec 3, 2019
    GLID3R82 likes this.
  45. mthawley

    mthawley

    Joined:
    Sep 7, 2018
    Posts:
    62
    Would Force Feedback count as an effect? ;)
     
  46. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    My Trello board has something similar to that already on it :D
    upload_2019-12-3_21-4-2.png
     
    GLID3R82 likes this.
  47. mthawley

    mthawley

    Joined:
    Sep 7, 2018
    Posts:
    62
    Will you be implementing positional audio for collisions?
     
    NWHCoding likes this.
  48. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,105
    That is actually a brilliant idea. Will do immediately.

    EDIT: Done :D Collision sound now plays at the point of collision.
     
    GLID3R82 and Rotary-Heart like this.
  49. mthawley

    mthawley

    Joined:
    Sep 7, 2018
    Posts:
    62
    Coolio!
     
  50. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    597
    Importing your asset into an HDRP (2019.3.0f1) project turns everything pink in the Island scene for example.
    Also right after import 5 error messages like this one appear:
    shader properties can't be added to this global property sheet
    and this one
    next vertex not found in checkwinding()

    Is it safe to automatically update all materials that ship with your asset to their HDRP siblings? Or should I do this manually?
     
unityunity