Search Unity

NWH Vehicle Physics 2

Discussion in 'Assets and Asset Store' started by NWHCoding, Apr 8, 2020.

?

What would you like to see implemented next?

Poll closed Feb 12, 2023.
  1. FMOD sound module

    0 vote(s)
    0.0%
  2. Tracked vehicles

    3 vote(s)
    30.0%
  3. Softbody wheels

    7 vote(s)
    70.0%
  4. Something else (mention in the thread)

    0 vote(s)
    0.0%
  1. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    it might be that the center of mass is slightly to one side or that the model is not fully symmetrical which causes it doe veer to one side.
    When setting up these vehicles I was going after realism and comparing them to games such as Factor 2 but for the next update I will loose up the slip coefficient of the demo vehicles by a bit to make them a bit more manageable. This can be done through the WheelController inspector (for both lateral and longitudinal friction).
     
    schaefsky likes this.
  2. hromoyDron

    hromoyDron

    Joined:
    Jan 24, 2013
    Posts:
    90
    Good afternoon.

    I have a problem. When the car drives along a terrain or large colliders everything is fine.
    But as soon as car drives onto small colliders, car starts jumping and flying off, colliders that car ran onto also fly off, as if an explosion had occurred. Why might this be happening?
     
  3. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    If the car encounters a collider at some speed and the height of the collider is higher than the suspension travel, and all this happens over one frame, the suspension will hit the bump stop exerting a collision force. That said in your case it seems that the obstacle is a Rigidbody too in which case the issue might be that the obstacle gets a force applied to it and flies off in some direction, possibly upwards as a result of the collision with the ground, and causes the suspension to compress repeating the cycle.
    I have to point out that the WheelController3D works on the principle of inverse kinematics meaning that the ground position is detected first and the the wheel/suspension position adjusted so that it lies on the ground.
     
  4. hromoyDron

    hromoyDron

    Joined:
    Jan 24, 2013
    Posts:
    90
    Yes, you are right. My obstacles are Rigidbodies.
    Moreover, obstacles can move. I use rope suspension bridges that a car can drive over.
    Сolliders on the bridge spring and move. It also makes the car jump.

    I understand correctly that the only way to fix jumps is to increase the value of spring max length?
     
  5. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    You could try disabling "Apply Force To Others" under WheelController but that will do what it says which will most likely not be satisfactory if you want the bridge to react to the vehicle. With the bridge oscillation might also be an issue.
    Increasing spring length could help and reducing Project Settings > Time > Fixed Delta Time will definitely help but will increase CPU usage as the physics will run more often (e.g. 0.1667 for 60Hz or 0.1 for 100Hz physics update rate).
     
  6. Swyfft

    Swyfft

    Joined:
    Mar 14, 2019
    Posts:
    55
    Hey .. looks like it's been a while since anyone said "Hi" here..
    Been prototyping with this for a bit now.. looks great .. learning stuff ..
    (also started playing with your Aerodynamics kit..)
    and I stumbled across the 'Tank' video from v1..
    curious to see if there is any update on Tanks for V2?
    Thanks for the great work!!!
     
  7. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hi :)
    Unfortunately I have not yet gotten to implementing the tanks in NVP2. The asset itself is designed to be able to add motorcycle and tank functionality in the future but this has been dragging on for quite some time now and I do not have any ETAs.
     
    Rowlan and Willbkool_FPCS like this.
  8. tang001

    tang001

    Joined:
    Aug 9, 2015
    Posts:
    8
    Hi
    I have a function and I don't know how to implement it.
    The function is like this, when the car is driving to a specific place, I need to pause the car, show a commentary to the user, and then resume, continue to drive forward. Does anyone know a better way to pause the car? tks.
     
  9. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Maybe this helps you: https://gamedevbeginner.com/the-right-way-to-pause-the-game-in-unity/
     
  10. tang001

    tang001

    Joined:
    Aug 9, 2015
    Posts:
    8
  11. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    In that case, it is a bit more complicated but doable. You first need to freeze the Rigidbody by setting velocity and angularVelocity to 0 and possibly constrain the Rigidbody. Then, you need to pause the VehicleController. The best way to go around doing this would be to put a toggle in Update(), FixedUpdate() and LateUpdate() that returns if the game is paused. Since all the aspects of the vehicle are controlled from these three functions inside VehicleController script it will pause the whole vehicle. So something along the lines of
    if (MyGame.Paused) return; 
    at the beginning of these functions.
    The last thing to do would be to pause the particles and this can be done by getting all the ParticleSystems from the child objects using something like GetComponentsInChildren().
    To re-start the vehicle remove any constraints on the Rigidbody and set the velocity and angularVelocity to the initial values so the vehicle continues moving as if nothing happened.
    This should work but has not been tested.
     
  12. tang001

    tang001

    Joined:
    Aug 9, 2015
    Posts:
    8
    I give it a try, thank you very much.
     
  13. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    By popular demand NWH Vehicle Physics 2 is getting Rewired input support with the upcoming v1.7.1 update.
    Update is expected to be out by the end of the week.
     
  14. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    New update is on the way:

    v1.7.1

    20/10/2021
    • Added Rewired support.
    • Disabled assembly definitions by default. All the .asmdef files now have .bak extension attached. Remove the extension to use the assembly definitions.
    • Fixed NRigidbody error when a WheelController is destroyed.
    • Fixed WheelController enable and disable not working.
    • Discrete Rigidbody collision is now default. Thanks to @vincurekf for discovering that Continuous collision was the cause for unrealistic high speed collisions.
    • Made all classes partial and more classes virtual for easier extension and modification of the asset.
    • Fixed GetInitSpatialBlend() always returns 0.9.
    • Clamped shift time to 0.02 to prevent 0 shift time which can cause issues with rev matching.
    • Added D/N/R selection through ShiftInto input.
    • Fixed error when no LODs are present on the vehicle.
    • Fixed TurboFlutter does not play random sound.
    • Fixed disabled WheelController continuing to simulate.
    • Fixed FuelModule using Update instead of FixedUpdate.
    • Removed WheelController Visual requirement.
    • Fixed assigning Visual after Initialization makes Visual not move.
    • Fixed Mirror RpcThrottleInput and RpcBrakesInput sending wrong values.
    • Added “AwakeOnStart” option to Settings > State Settings. This determines the state of the vehicle after Start().
    • Increased maximum steer angle value.
    • Updated PUN2 documentation.
     
  15. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96
    Hey, I've been testing the physics in a simple scene, but I could not figure it out how can I use NWH Vehicle Physics on a car that consists of multiple body parts (rigidbodies). I'd like to make a car that can literally fall apart. Also, I'd like to hang the wheels on separate objects with separate rigidbodies that are put together by joints.

    Can I do that? How? First I thought it's a simple thing to make (and maybe it is) but I can see that I need to refer to a single ridigbody to use the car physics.

    Thank you.
     
  16. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    the VehicleController itself needs to have a single Rigidbody as its parent. You can then attach car parts to that main Rigidbody through physics joints. Physics joints are the only way to have two Rigidbodies stay together. However, this approach is rarely used since the joints always have some play - check out the Kerbal Space Program where the rockets are held together by joints and there is always some wobble present. More common approach would be to not use Rigidbodies until the part needs to fall off and then attach a Rigidbody to the part (e.g. door) and let it start simulating physics.
    As for having separate Rigidbodies for wheels - this will not work without some code modification as the whole VehicleController and NRigidbody (physics sub-stepping) approach is quite tightly integrated and by design.
     
    Yany likes this.
  17. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96

    Thank you for your reply. So I can use WheelController 3D to hang them on separate (and jointed) rigidbodies, but I can not use NVP to control this kind of car (at least yet), right? Can you give me a hint what should be modified? Is it a tough thing? :)

    Thank you.
     
  18. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The WheelControllers can be used separate from the VehicleController for things like trailers or generally attaching them to anything that has a Rigidbody. It is when you use them with VehicleController that a lot of things get calculated from the wheel positions - e.g. wheel geometry, ackerman steering, vehicle dimensions, etc. In short everything works more as a unit.
    The NRigidbody complicates things a lot since it is used to sub-step physics for the friction calculation and makes things even trickier. So I would suggest against this as it is not a simple modification.
     
    Yany likes this.
  19. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    Have the demos on your website been updated to use the latest version?
     
  20. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Demos are mostly for v1.7 (currently on v1.7.1). But the latest update was mostly a hotfix so I did not rebuild everything.
     
  21. tang001

    tang001

    Joined:
    Aug 9, 2015
    Posts:
    8
    Hello, my project has a very special requirement: when the vehicle is going uphill, I want to ignore the influence of the gradient on the vehicle speed, that is to say, the same throttle level, the vehicle speed is the same on flat ground and uphill. Is there any way to do it? thanks.
     
    Last edited: Oct 29, 2021
  22. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    From the physics aspect the only way to do this would be to set gravity to 0, but that is probably not what you want.
    You can however use the CruiseControl module that is included. That will keep the speed constant. But you also mention that you want the throttle to be constant which is quite confusing since the throttle is what controls the output power of the vehicle and more power is needed to climb a gradient than to drive on flat ground.
     
  23. stojic

    stojic

    Joined:
    Feb 11, 2016
    Posts:
    3
    can you tell me how to camera zoom using touch screen in scene input actions
     
  24. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Pinch-to-zoom is not implemented in the demo input code so you will have to do this part yourself.
    I would suggest either modifying one of the existing InputProviders or making a new one and overriding the
    CameraZoom()
    function with the code for the wanted behaviour. Also, this section of docs might be relevant: http://nwhvehiclephysics.com/doku.php/Setup/Input#Scripting
     
  25. viemr

    viemr

    Joined:
    Oct 24, 2016
    Posts:
    3
    Hello, we're trying to implement AudioKinetic's Wwise framework into a project that uses NWH Vehicle Physics 2. However there seems to be some kind of conflict as a project containing both packages won't build. Anytime a build is made there will be 4 errors about missing sound effects for Wwise (something that doesn't happen without Vehicle Physics 2).

    This has also been tested in a fresh unity project containing just NWH Vehicle Physics 2 and Wwise.
    Is this a known issue to anyone else? And if so how could this be fixed?
     
  26. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    NWH Vehicle Physics 2 definitely does not do anything weird related to audio. Upon import a number of sound files and an audio mixer are imported, along with the audio-related scripts. The thing that could be the culprit is the Unity importer itself. It does not check if the files are in different assemblies or namespaces so it could be that something somewhere is getting overwritten. To check if this is indeed the case import one package and then when importing the second package check if any of the files have the "reimport" icon next to them (similar to the recycle sign).
     
  27. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I am happy to announce that NWH Vehicle Physics 2, Dynamic Water Physics 2, and NWH Aerodynamics will be 50% off from November 14, 2021, 21:00:00 PT to December 4, 2021, 23:59:59 PT.
    More info about the sale here.
     
  28. Vancete

    Vancete

    Joined:
    May 3, 2010
    Posts:
    198
    Will racing AI added to the package? Even as a separate package?
     
  29. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Not in the plans currently. However, the input has been structured in a way that makes 3rd party AI easy to implement. There are Horizontal and Vertical axis available that are enough to completely control the car movement so as long you can get the two out of the AI you should be good to go.
     
  30. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    How does Rewired support work ? Can you explain ?
    I imported your Rewired package. Setup some joystick maps in rewired. Added RewiredVehicleInputProvider script in the scene. But there is no response to the input in vehicles.
    Do i need to use New Input System ? Normally Rewired doesn't support new input system.
     
  31. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello, have you checked the section in the docs about this: http://nwhvehiclephysics.com/doku.php/Setup/Input#Rewired_Input_Provider ?
    I have included the already set up Rewired Input Manager for vehicles so the maps are already in there.
    InputSystem is not required by the Rewired InputProviders but is required by the asset itself since the default input method for most of the demo content is InputSystem. So it is best to set Project Settings > Input Handling > Both.
     
    kopanz likes this.
  32. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    I own a custom softbody physics engine for Unity based on Jitter physics engine. It samples thousands of points per second from Unity terrain without creating any memory garbage. I use Terrain.SampleHeight(), Terrain.terrainData.GetInterpolatedNormal(). Those functions doesn't generate any GC.
    I even modified Jitter physics to have zero garbage in it's physics loop :)
    Also the memory leak i mentioned is a lot bigger than 136B per frame. It's about 6.7KB per frame.
    This is from NWH Racetrack demo.
    vehicleController.JPG
     
    Last edited: Nov 16, 2021
  33. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Ah, you probably have an older version for Unity 2019.4 LTS (the newest one is 2020 LTS only).
    This is in-editor screenshot of v1.7.3 (latest):
    upload_2021-11-16_19-54-38.png

    The GC you are seeing is due to the Debug.Assert() statements that were removed in the meantime to avoid causing garbage in editor. They do not have any effect in release builds.

    Also, the rest of GC (about 10B per wheel per frame) is from TerrainData.GetAlphamaps() (more accurately TerrainData.Internal_GetAlphamaps()) and GameObject.get_tag(). Both are inside GroundDetection so if this is an issue disabling that VehicleComponent will get rid of it.
    Lastly, there seems to be a small source of GC in SoundManager and that has been introduced with the last 2 or 3 updates so I will check what is happening there for the next update.
     
  34. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
    It's Unity 2020.3.f14 :) I'm not saying it's very bad. But i'll try to remove any GC generation. Because when the garbage collector runs it really pauses the game. Some people hate Unity games for this.
    No need to be alarmed about my feedback. You have a great product.
     
  35. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I do have a 0 GC policy and I have failed to check the GC before submitting v1.7 which resulted in minor amounts of GC as you can see. Optimization is something I take quite seriously and GC is not good for performance. In the pre v1.7 only the Terrain call caused GC (and one or two demo-only scripts such as FPS counter) so I will check what changed in the meantime.
     
  36. facundogalella

    facundogalella

    Joined:
    Mar 5, 2016
    Posts:
    59
    Hi! I tried the asset yesterday, looks really nice, even compared with NWH 1.

    Just I'm struggling a bit with the inertia when I release the gas pedal, I'm not sure how I can reduce the speed more quick in this situation. The car keeps with almost the same speed and due I'm working with an electric car would be nice feel a sort of brake in this situation.

    I reduced the inertia of many components and also I added the aerodynamic module but is not enough.
     
  37. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The inertia setting is not what will help you in this case. Inertia mostly affects how fast the powertrain components speed up / slow down (angular velocity) but what you are looking for is powertrain drag. Currently, this is calculated automatically inside the EngineComponent. In older versions it was adjustable and I am planning to add the option again for v1.7.4. At the moment only adjustable drag is tire rolling drag (under WheelController) so that might do the trick until the update rolls out.
     
  38. facundogalella

    facundogalella

    Joined:
    Mar 5, 2016
    Posts:
    59
    Thank you! Would be nice have it again if possible to simulate the 'lift and coast'. Meanwhile I'll check the tire rolling drag
     
  39. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Powertrain drag is calculated, just not adjustable. I will see that this field is exposed again. It got lost somewhere along the way.
     
    facundogalella likes this.
  40. ntc-tor

    ntc-tor

    Joined:
    Apr 20, 2020
    Posts:
    6
    Hi!

    I faced an issue when I switch gears (with manual clutch) sometimes the transmission component breaks like real thing. What I mean by that is a GetCurrentGearRatio() returns 0. And I can fix it only with a respawn.

    So I wander maybe you can guide me how to solve this issue without using respawn of a vehicle =)

    I try to simulate a very heavy vehicle like the rocket carrier from a demo. But it weighs a twice more like 40k with wheels 200 kg each. I try to stay close to real world vehicle properties.
     
  41. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    If you are getting GetCurrentGearRatio() == 0 you are definitely out of gear.
    Could you check that? If your gear ratios are not 0 it should definitely not return 0 while in gear.
     
  42. ntc-tor

    ntc-tor

    Joined:
    Apr 20, 2020
    Posts:
    6
    I was able to record a video


    first minute -- go through basic vehicle setup and gear switching
    ~15 min of driving ( lol )
    I also setup a unity event on gear switch to print to console current gear ratio. It visible at the bottom on the screen.
    on ~1:13 current gear ratio starts to show 0. No matter which gear I choose. Well to be honest it rapidly jumps from 0 to a correct gear ratio and back again.

    What I did, I made a right turn on 9th gear and almost full throttle.
     
  43. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Besides the data that you have shown I would also check what gear the vehicle is in when the gear ratio falls to 0. Are you using manual shifting through a physical gear shifter (e.g. Logitech) or keyboard input? This to me seems more like an issue with going to neutral as the code for returning the gear ratio is quite simple and is not the reason for the issue.
    So a few things to try:
    - Does it happen with keyboard-only input (0-9 to select gears, with controller disconnected)? My guess is no.
    - When that happens does it go into N / neutral / gear 0.
    If it happens with the keyboard too I would also try increasing VehicleController > Settings > Substeps due to the extreme gear ratios and weight of the vehicle, to see if this will fix it, but this would have more effect at speeds near 0 and it happens at quite a speed in your case which is interesting.
     
  44. ntc-tor

    ntc-tor

    Joined:
    Apr 20, 2020
    Posts:
    6
    Well I have very weird input by historical reasons.

    Anyway. it works that way:
    I have a structure with input data. This structure updates through network.
    And I assign values from this structure to vehicle input states in standard update loop. So there is no keyboard, wheel or controller input.

    Here the video:
    from 0 to 00:30 -- about input
    ~ 00.37 - transmission fails
    Also there you can see, that input structure does not change. A transmission field contains gear value.
    ~01:51 - I tried to switch gears


    I also tried increasing substeps. But it will take a few days of testing. This condition takes a really long session to reproduce.
     
  45. kopanz

    kopanz

    Joined:
    Dec 6, 2016
    Posts:
    82
  46. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    ntc-tor and kopanz like this.
  47. paulixx

    paulixx

    Joined:
    Dec 4, 2020
    Posts:
    1
    Hi, first things first: really great asset and great work!!
    I'm trying to get a steamvr camera rig to work. But how can i do this?
    I read the documentation wich says in the camera section there is a "camera changer" where i can add a camera. But there is no "camera list".
    The scripts says "public List<GameObject> cameras = new List<GameObject>();" but no list appears in the inspector. So i dropped the steamvr CameraRig as a child into "Cameras" and was hoping i can access it over "index". No success.
    Wich is the right way to apply vr?

    Unity 2020.3.4f1
     
    Last edited: Dec 11, 2021
  48. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    I would like to clarify that the cameras are completely separate from the VehicleController and you do not have to use the provided cameras or the provided camera changer. You can attach any camera script to the vehicle. So just setting up the SteamVR rig as you would with a basic GameObject will work perfectly fine.
     
  49. isNewBird

    isNewBird

    Joined:
    Mar 27, 2019
    Posts:
    20
    hello

    I have such a problem and would like to ask for your help.

    1. I have an AI vehicle that synchronizes the location of my vehicle, but it doesn't have NWH mounted.

    2. My vehicle is mounted with NWH and then passes its position to ai. Because my own vehicle has suspension, causing the vehicle to lift up

    The value passed makes the AI levitate.

    I would like to ask how CAN I get the vehicle position parameters that are not affected by suspension?

    Thank you
     
  50. isNewBird

    isNewBird

    Joined:
    Mar 27, 2019
    Posts:
    20
    hello

    I have one more question

    I want to cancel engine jitter. Where do I need to turn it off?

    Thank you