Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Edy's Vehicle Physics - official thread

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

  1. BusterTheWizard

    BusterTheWizard

    Joined:
    Jul 2, 2012
    Posts:
    55
    Interesting, this may be easy to integrate then. RCC does use friction and constantly adjusts it, that and many classes all individually trying to access info about the wheel collider are what make integrating it a pain. Sounds like EVP would be a lot easier to do it with. I'll give it a shot, if I figure it out I'll share it here for others.
     
    Edy likes this.
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    For a "compensating fifth wheel" coupler, you are correct. A "standard" fifth wheel coupling on many trucks will not include rotation on the axis parallel to the travel (Z). The whole trailer will tilt a little if the tractor tilts, like hitting a curb on the right side. Small amounts of twist is absorbed in the suspension at each axle.
     
    Edy likes this.
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    This is extremely interesting. I always assumed there should be some rotation parallel to the travel, but what you said makes total sense. Thanks!
     
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    Edy, do you have advice on making an EVP vehicle a little less prone to getting out of control when all you have are on/off inputs? Keyboards and the L/R triggers of a Switch Pro controller aren't proportional, so I'm finding it hard to get the right lerp magic to get up to a good moderate speed (below the vehicle's own max speed) and similarly for WASD steering. More Lerp and less Lurch but not horribly slow to get motion too.
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    If you're using the VehicleStandardInput component, then all the "lerp magic" is configured in the standard Unity input settings. Check out the recommended settings here:

    https://evp.vehiclephysics.com/faq/#how-to-configure-the-input-parameters

    With these settings in the horizontal and vertical axes, vehicles with good settings are pretty fun to drive (at least the example vehicles included in the package).
     
    halley likes this.
  6. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    Yeah, it wasn't the physics parameters or the purpose of the brake/throttle/steering parameters that confused me. But I see your VehicleStandardInput input code (and your commented block re: a better continuous forward/backward handling), and that gives a good insight on how to handle that.
     
    Edy likes this.
  7. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Hey Edy. This could be a pretty dumb question to vehicle gurus, but that i am not. Is it possible to get a rough estimate of horsepower for any one given vehicle, as it is now, i only really see max drive force as a viable property for the general power. But for eg: 5000 to max drive force doesnt really translate to much i recognize.

    I suppose i could do some fake maths and come up with a number (i did recently check out a few sport cars . horse power etc for comparisons) but still, the numbers in the end didnt seem to match up.

    Im not sure what numbers i should be crunching, but i did locate this equation.
    Power = Force * Distance / Time.

    UPDATED: Disregard, i managed to crunch some numbers and find what i needed. Ty.
     
    Last edited: Mar 14, 2023
  8. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,671
    Can you share the answer? Your question seems like a good one. :)
     
  9. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Yea, sure, but bare in mind,

    #1 a vehicle guru i am not,
    #2 a math genius i am not..
    #3 this is not a true formula for HP, the real formula would be Force(#Pounds) * distance / time. But i still havent wrapped my head around how to work in the vehicle weight, and frankly, the results i am getting are really close to what i would expect based on my general browsing of vehicles.

    That said, i did manage to find what appears to work for me (i only needed a semi believable value to represent my vehicles, as they are not realistic to begin with.)

    If you take the max drive force, multiply it by 100 (Neuton) and divide it by 735.49875, it will result in a semi believable value. Do be ware, that the max forward speed may or may not need to be adjusted over all as well to compensate for your increased / decreased power, as they are indepenent properties.

    If anyone else comes along and sees this, and IS a math / vehicle wiz, i would appreciate any tips on how to truly aquire any result even more accurate.
     
    hopeful likes this.
  10. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    I now have another question Edy. Is there any way you can provide some additional information on exactly what, and or how, a few settings work.

    Mostly, im interested in the GearDownRPMRate, GearUpRPMRate, and their relation to gearUpRPM, gearDownRPM, IdleRPM, and maxRPM.

    Obviously, the latter four are fairly self explanatory, but exactly what is those Rates doing in this picture.

    Cheers.
     
    Last edited: Mar 17, 2023
    Crossway likes this.
  11. noio

    noio

    Joined:
    Dec 17, 2013
    Posts:
    226
    I have a question about driving uphill in Edy's Vehicle Physics (EVP) package for Unity. I'm finding it difficult to model uphill driving realistically because there is no gear shifting in EVP. As force in EVP depends on speed and not on internal RPM, I'm not sure how to accurately simulate uphill driving for a vehicle.

    When I say 'accurate' I don't mean fully realistic. I just find it tricky to model a single Force Curve Shape (incl Max Force & Max Speed) that gives satisfying behavior both on flat land while still being able to drive uphill at all. If I bias the curve to give high force at low speeds, the car drives uphill fine but it accelerates way too fast on flat land, and vice versa.

    Would manually swapping the Force Curve Shape when detecting an uphill drive be a possible solution? Essentially, this is modeling a gear shift.

    Alternatively, should I consider switching to VPP? I'm really happy with EVP's abstraction level and would prefer to stick with it if possible.

    Any advice or suggestions would be greatly appreciated. Thanks in advance!
     
  12. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    I thought I was going nuts for a bit (maybe I am). Tried to add EVP to a forklift but the forks wouldn't collide with anything. Finally came to figure out that all the colliders on the fork mast had been moved to layer 2, and that I could avoid that branch in the logic by setting my wheel update mode to "Fast." All the code looks like the layer 2 ("Ignore Raycast" by default) stuff should just be done for brief moments, but something is not restoring them as they should be.
     
  13. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    Those define the rate of change of the engine audio pitch when gear is switched down or up.

    A higher rate makes gear shifts sound more "abrupt", like in sports cars, while a lower rate makes them sound more smooth, like in family cars with automatic transmissions.
     
  14. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    Actual force in cars depend in both the engine and the gearbox. Having to gear shifts up means each gear provide more speed but less force than the previous one.

    As a result, typical realistic force curves have this kind of shapes (shape < 0.5):

    upload_2023-4-7_12-23-45.png

    This provides good acceleration and speed on flat ground, but will force the car to decrease the speed on uphills in order to gain some more force.

    Remember that the curve is heavily related with the maximum speed setting (meters per second) and the aerodynamic drag, which prevents the speed to actually reach the given max speed.
     
    noio likes this.
  15. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    That might be a bug, will take a look at it.
     
  16. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    How can I record car movements?
     
  17. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    Most reliable method is storing position, rotation and inputs each fixed update. If you also want to restore the state from an arbitrary state ("flashback"), you should then include velocity and angular velocity.
     
  18. TwentyOneGamesStudio

    TwentyOneGamesStudio

    Joined:
    Jul 10, 2020
    Posts:
    5
    What is the use of FollowHeading.cs Script in of Edy's Vehicle Physics, For what Purpose we can use it?
     
  19. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,480
    This scripts controls the vehicle's steering to keep the vehicle driving in the configured direction, in degrees. 0 is North, 90 is East, etc.
     
    TwentyOneGamesStudio likes this.
  20. balto2k13

    balto2k13

    Joined:
    Sep 2, 2023
    Posts:
    1
    Hi,

    I am having a problem with the 'Wheel Transform' , I set it to my wheel meshes respectively (FL,FR,BL,BR) however when starting the game they all go the origin of the vehicle instead of where they are placed in the editor, I've taken a look at the included prefabs and can't see why they work versus why my model doesn't.

    Any idea on how to get this working properly? Thanks.

    Edit: Got it fixed, for anyone wondering I was modelling in Blender and I needed to apply all transformations (scale,rotation etc) and also make sure the axis matched the model. And in Wheel Collider the 'Center' had to be 0,0,0 and I moved the transforms xyz axis.
     
    Last edited: Sep 2, 2023
  21. Slimmy

    Slimmy

    Joined:
    Apr 25, 2017
    Posts:
    21
    Hello!
    When the vehicle is traveling at high speeds steering is being manipulated somehow and the vehicle understeers terribly. How can I disable or lower the effects of this behaviour?
    Also, when vehicle is damaged it tends to steer to one side. How can I disable this?
     
  22. Slimmy

    Slimmy

    Joined:
    Apr 25, 2017
    Posts:
    21
    Am I correct in assuming that Steering Limit should control the understeering? I've tried turning it on and setting the value to 0 to see if there's any difference. Also set it to 1 and of course had it turned off completely. But, I cant tell any difference.
     
  23. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    177
    Hello All,

    after upgrading to Unity 2022.3 LTS i start having "stutter" when driving my vehicles using your assets.
    Unity seems to introduced some changes to the physics system so that could be the cause but dont know what i have to do to fix it.
    Everything was working great in older version of Unity.

    Any idea on what can cause this?

    May thanks
     
    Gametyme likes this.
  24. MagyarPeter

    MagyarPeter

    Joined:
    Nov 28, 2020
    Posts:
    11
    stutter? do you mean low FPS but only on the vehicle? I have the same issue but only on the mobile build, it's fine in the editor.
     
    Gametyme likes this.
  25. iiElricc

    iiElricc

    Joined:
    Feb 20, 2023
    Posts:
    5
    Hey there

    How do I switch control from PC to mobile control in Edy's vehicle physics or vehicle physics pro

    I'm also a beginner in game development & I know little, I need ur help

    Thax
     
  26. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    Returning to this topic after a break. Another solution I never found from Google, but makes total sense in retrospect. Explaining it here so Google has a chance to find it for others.

    If you want to DISCONNECT a Joint, the usual explanation is that you must DESTROY the Joint, because 3D Rigidbody and Joint components have no "enabled" flag to turn them on and off. But that's a pain in the rear if you want to RECONNECT a Joint later, because you have to configure the whole darn thing from scratch, and for Configurable Joints, that's a lot of hardwired code to maintain.

    Instead, to DISABLE a Joint, just give it a replacement "dummy load" on the Connected Body field. One gram, one kilogram, doesn't matter, but just keep a spare invisible colliderless Rigidbody around. Move it to the anchor point, set it kinematic=false and set the parent to null. Switch the Joint's Connected Body to the dummy body, and boom, your trailer is disconnected and your truck won't be magically anchored to the world. And it's reversible: Line up your trailer the way you like, and switch the Joint's Connected Body to the trailer. I made a quick component that can manage the dummy load object and connect/disconnect a real object for any joint.

    This is of course applicable to more than just trucks and trailers.
     
    hopeful likes this.
  27. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    And now that I am happy pulling a trailer, I am even more happy to discover that a spline-following Rigidbody is able to tow the whole truck! Just put a kinematic Rigidbody ahead of the truck's front bumper, give it another Joint to attach to the truck, and start hauling it along whatever path you like with Rigidbody.MovePosition. Up and over bumps, lurch and lean in the corners. And amazingly, all of the Edy's engine movement code triggers the correct audio stuff based on the movement speed, not the throttle setting or inputs, so all the audio and wheel code just does the right thing. I think there's no reason this can't be done with a Timeline or other animation techniques.

    This enables NPC "driven" vehicles, or autonomous background vehicles.
     
  28. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    I’m also experiencing stuttering in the pc build but editor is fine.
     
  29. iiElricc

    iiElricc

    Joined:
    Feb 20, 2023
    Posts:
    5
    Hello all
    How can I make a truck trailer physics with Edy's Vehicle Physics or Vehicle Physics Pro
     
  30. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    Start one page back in this thread, starting with this post and later ones I posted.
     
  31. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,282
    I ran into another car model which somehow had all the colliders change to Layer 2 (IgnoreRaycast) permanently upon game startup. I knew the issue must be in VehicleController.cs and something to do with the way ground raycasts were done, and had seen the DisableCollidersRaycast() code before, but didn't really think about it.

    At 4am this morning, I woke up and realized how the single loop in that method was broken. In old Unix days, you'd say that the single loop was clobbering data, in the case that a single GameObject had multiple colliders on it. The first collider would be saved as layer 5 and set to layer 2. The second collider would be saved as layer 2 and...

    before.png

    An alternate fix would be to reverse the direction of one of the methods' loops, either one, and letting the clobbering happen. I feel this code makes it a little more clear without a ton of overhead.
     
    Last edited: Feb 2, 2024
  32. iiElricc

    iiElricc

    Joined:
    Feb 20, 2023
    Posts:
    5
    Do you have a tutorial vid ..