Search Unity

Games Vehicle Physics Simulation (Update 20-Feb-17 Terrain Editor Preview 1)

Discussion in 'Works In Progress - Archive' started by AndersOrum, May 6, 2015.

  1. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Hi guys, small update on some of the stuff i've been working on this week, i'm working on a debugger system for my softbody based vehicles, this system allows me to check chassis and parts for stress.

    Visability increases as stress raises
    Red link = Compression
    Blue link = Stretching
    Dark Blue/Black = Deformed

     
    Cristineltr, John-G and sjm-tech like this.
  2. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Hi guys i've started working on a new vehicle AI system last week here's the current progress, currently it features 4 different modes:

    1. Chase: They will try their best to wreck you
    2. Follow: Usefull for convoy driving
    3. Checkpoint: They will follow a predefined route(route can be changed during runtime)
    4. Flee : They will try to get away from you(not shown in video)
    This is just an early test many improvements coming soon!

     
  3. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Finally time for an update on my terrain physics system, this video is a early test of the new updated system, many improvements have been made since my last video on the terrain system:
    - It now works with 2 physics engines PhysX and Truss, and can run both simultaneously or just engine alone.
    - Added terrain mesh generation based on terrain heightmap.
    - Added runtime terrain mesh deformation based on heightmap, this is used if the terrain only is deformed in Truss physics, in that case the Terrain Component isn't needed, and a mesh will be used render the terrain instead.(this currently used in the video)
    - Added terrain tiling support.
    - Massive performance upgrade.
    - Because of tiling support and the performance upgrade, the detail of the terrains collision mesh is now 6-7 times higher, and could be increased even further without much effect on performance.
    - Improved the terrain physics model(still based on a simple model, but will be improved a lot later).
    - And many many other changes.

     
    devotid, mbowen89, newlife and 3 others like this.
  4. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Back with another update on the terrain system, i've made a bunch of improvements since yesterday:
    - Improved terrain physics model, earlier only weight/load on the terrain would affect the deformation, now weight, velocity, lateral & longitudinal slip affects the deformation.
    - Fixed many visual bugs on the generated terrain mesh( specially light and shadows).
    - Small optimizations.

    Hardware specs:
    CPU: Intel i7 4790k
    GPU: Nvidia GTX 970
    RAM: 16 Gb

     
    Cristineltr, StephenL and Slipangle like this.
  5. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Just curious, how performance heavy is this then? Even close to mobile capable?
     
  6. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Honestly i have no idea how fast mobile phones cpu's are today compared to cpu's in computers, in theory it should run on mobile but i think it's a bit too cpu heavy, but there is also plenty of room to scale down the accuracy of the physics to gain performance, currently my vehicles is about 75% node/beam density compared to BeamNG.Drive (though my vehicles is still missing many parts of cause) this could be scaled down a lot while still keeping decent softbody deformation and behavior, also the physics is running on a very low fixed step(world/terrain 0.005, vehicles 0.00125) to allow high accuracy at high velocities, this also could be increased to gain a big performance boost.
     
  7. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Ok. What was your plans with this project? Making a game? Selling an asset?
     
  8. Cristineltr

    Cristineltr

    Joined:
    May 15, 2016
    Posts:
    13
    Your work is awesome and it was an inspiration for me to start to work on my own game.

    How many trucks like the one in the video can you use in the scene before the fps drops below 60 or better how many nodes, beams and faces ?

    Also did you do any modification to truss physics to improve the performance in any way?
     
  9. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    My plan is to develop this vehicle and terrain system with the intention to make my own game based on these systems, later i will be open to license it to simulation software, and maybe sometime in the future sell/license it to game developers.


    Thank you, yours is looking very good too!

    Currently i can run 3-4 active AI/Player controlled trucks at about 60fps, a rough estimate i'd say it's about 4000 nodes 10000 links and 3000 faces.
    But it's the collisions that really eats the performance.

    I've made many changes to the implementation of Truss, some of the changes were performance improvements, but these changes have already been reported to the author of Truss physics, and there are already implemented or will be in the next public Truss release.
     
    antoripa and Cristineltr like this.
  10. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    - Just to be clear, these numbers only counts when i'm using a static terrain and with much less detailed collision mesh. On the deformable terrain i can do 2 trucks about 100 fps, a third truck kills the frame rate, again it's the collisions that eats most of the cpu, the actual deformation is quite fast.

    Yet another update on the terrain system, i've made a few improvements to the soil model and added a few debugger views.
    - Deformation is now calculated on all contact/collision points, before it would only use the average position of all the points and calculate deformation from that position.
    - Added new variable to the soil model "surfaceStrength", this controls how much force it takes to break through the surface layer.
    - The soil now becomes harder as it gets more compressed, this is currently a linear scale but will be tweakable later.
    - Tire friction is now accounted for in the deformation calculation, so now a heavy threaded offroad tire will carve up more of the terrain when is spins than a highway tire would.
    - Fixed a bug which caused the tires to continue compressing the terrain if the vehicle wasn't moving or tires rolling.
    - Added 2 new debugger modes:
    1). Wireframe View.
    2). Tile Activation View - Green = Active, Red = Disabled, this shows you which terrain tiles currently is active and being deformed.

     
    Last edited: Jan 19, 2017
    StephenL and Cristineltr like this.
  11. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    So you basically have a tiled terrain system, and the wheels are modifying a heightmap for that specific terrain tile that it is interacting with? And then modifying the verts with a dynamic mesh?
     
  12. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Yes on each physics step i collect all contacts on all terrain tiles within x distance of an active body, if all 4 wheels are touching the ground that would mean 4 contacts, 1 contact lets say a tire touching a terrain tile usually have somewhere around 10-40 collision points but could be up to several hundreds points(depending on tire pressure and the terrains geometry), so for every contact i collect all the collision points and calculate deformation on each point, this is done for any type of body shape. Then on each Update for all active tiles i convert heightmap heights into world space coordinate and apply that to the mesh rendering the terrain, this is currently done one the cpu and is actually one of the slowest parts of the system, so i hope to move that to the gpu at somepoint but currently i'm not experienced with shaders.
     
  13. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Well the best looking and possibly easiest thing would be tessellation of course, since it creates more geo on the fly and is adjustable. Or just modifying the verts in the vert shader according to whatever the latest heightmap is.
     
  14. MonkeyPuzzle

    MonkeyPuzzle

    Joined:
    Jan 17, 2016
    Posts:
    119
    Looks great mate. The four wheeling video looks really promising - Is there a game out there that focuses on off-road climbing? Seems like a natural. Nto much to crit. I would love to see trucks breaking through physics based bariiers, walls, etc.
     
  15. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Yes that's what i thought, i'm now using MegaSplat which also supports Tessellation so i will soon look into that.

    Thank you! Spintires is the closest you get to something like this i would say, but Spintires isn't actually about rockcrawling and 4x4s it's focus is mudding in old russian logging trucks, but the modding community seems to be more into 4x4's and rock crawling.


    Terrain System Update 5:
    So the last couple of weeks i've worked on a couple of things but the biggest new feature is implementing MegaSplat, a new texture/shader system by Jason Booth, with this system i can now paint up to 256 different textures per terrain tile, before i could only do 1 texture per terrain tile, the idea is all these different textures as different soils, so each texture will make the terrain behave different based on the soil type connected to that texture.
    - Implemented MegaSplat.

    - Implemented runtime terrain texture painting(Although MegaSplat already includes a well optimized system for runtime painting, it wasn't quite fast enough, so i've made a simplified and optimized version, the result is about 10 times faster so painting 1 tile only takes about 0.005ms(see hardware specs below), the biggest factor for this optimization is the fact that i already know the positions of all vertices, so by converting collisionPoints world positions into terrain/heightmap positions i can then use those positions as indexes in my arrays instead of looping through all the vertices in the mesh, this saves me of several thousands calculations per tile per frame.

    - Started adding support for multiple soil types per terrain tile, it will be possible to have a different soil type per texture/heightfield coordinate( 1 heightfield is ~12x12 cm each tile ~4x4 m have about 1000 heightfields).

    - Many optimizations to the physical deformation, especially big optimization to multiple deforming bodies, meaning i can now have 2 active trucks deforming terrain at about 150-200 fps up from about 100 fps before, and 3 active trucks at about 50-80 fps up from 5-20 fps before..

    Hardware specs:
    CPU: Intel i7 4790k
    GPU: Nvidia GTX 970
    RAM: 16 Gb

     
    antoripa, StephenL and Cristineltr like this.
  16. antoripa

    antoripa

    Joined:
    Oct 19, 2015
    Posts:
    1,163
    Hi,
    excellent showcase.
    What is the terrain setting ?
    Do you only repaint or even adjust heightmap ?
     
  17. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Thank you,

    The 3 main things happening is:
    1. Heightmap deformation/adjustment every physics step(this is what changes the collider of the terrain).
    2. Mesh deformation/adjustment every frame(this is the visual mesh you see, it's a 100% exact copy of the collider/collision mesh).
    3. Mesh texture painting/adjustment every frame.
     
    antoripa likes this.
  18. antoripa

    antoripa

    Joined:
    Oct 19, 2015
    Posts:
    1,163
    Excellent ..sending a PM
     
  19. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Terrain System Update 6:
    This week brings a small but important update to the terrain system. The most important new feature is "Terrain Tile Stitching" you've probably already noticed in my earlier videos the gaps that appears between terrain tiles after deformation have happened near the edges of the tile, this was a very serious issue because it wasn't just a visual bug the same thing happened to the collision mesh, the new stitching feature fixes this issue on the collision mesh which automatically fixes the visual mesh as well.

    - Implemented terrain tile stitching. See first 30 seconds of the video i'm driving at the edge of a tile, earlier this would have caused big gaps to appear between the tiles.
    - Reduced GC allocations from an average of 2 kb per frame down to an average of 80 bytes per frame.
    - Improved texture painting, this is now based on depth of compression, which means the second layer(dirt) becomes more visible as you dig deeper.

     
  20. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Terrain System Update 7:

    I've been working on a lot of changes the last couple of days, but let me start by giving a big thanks to Viktor (aka Heartbroken) the developer of Truss Physics for the outstanding support he's been giving me lately on feature requests and bug reports. This week he made a very important update which i'm currently testing; friction material based on the terrain alphamap layer, this feature allows you to set different friction materials to be used for each texture. It's very flexible so it was easy for me to convert my mesh based terrain data into a format readable by Truss.

    This feature is also what i've been waiting for to implement my per vertex/texture soil type system i've been preparing.

    So to sum up, i can now have up to 256 different textures per 4x4m terrain tile, each texture with unique friction and soil settings connected to it.

    - Per vertex/texture friction material.

    - Per vertex/texture soil material.

    And also while testing some different tire sizes, i realized i've unintentionally already roughly accounted for surface area of a contact in the deformation calculations, which means a narrow tire will sink more into soft ground than a wide tire would because the wider tire spreads out the load to a larger area, i'll try to make some improvements to this and soon do a update on this.

     
    StephenL and antoripa like this.
  21. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Terrain System Update 8:

    So, just a quick little preview of a cool new feature i've been working on today, this started with me trying out MegaSplat's Tessellation Displacement and Parallax, these features lets you displace the heights of your meshes using a heightmap texture based on the diffuse texture (as far as i understand), however the problem with these techniques is that they run on the GPU which means i can't access the modified mesh data on the CPU, this is a problem because i need access to that data in order to modify my terrain collider based on the mesh.

    So i've come up with a new feature that does pretty much the same as parallax or tessellation displacement(displacing heights based on a texture), but instead this runs on the CPU which means i can take the modified mesh data and turn into a collider and make all the changes permanent on all terrain tiles from. There's still a few challenges with this currently it only works with 1 texture per tile and with a fixed uv scale, but with time i'm sure i'll figure out how to make it work seamless with the rest of the system.

    The visual mesh and collider stays 100% the same and there's no effect on performance for a complex shaped collider vs a flat one.

    I've also worked a little on memory usage and i've managed to reduce memory usage per terrain by ~35%, but there's still a long way to go here.

    Vehicle System:

    - Fixed a bug in the "Open Differential Lock" it will now calculate resistance on each halfshaft/wheel as intended.

    Hardware specs:
    CPU: Intel i7 4790k
    GPU: Nvidia GTX 970
    RAM: 16 Gb

     
    StephenL likes this.
  22. AndersOrum

    AndersOrum

    Joined:
    Aug 31, 2014
    Posts:
    49
    Terrain System Update 9:

    A small preview of a new powerful feature i'm working on, this will turn boring flat terrains into nicely detailed terrains with heights based on the texture used on each vertex, this gives me detail in the terrain which i never would be able to achieve doing it manually no matter the hours i'd put into it, but with this just a few minutes work gives you incredible results. At the startup of the application/game a heightmap based terrain collider is created from the mesh as a 100% precise copy.

    New Features:
    - Per vertex heights painting based on texture on the vertex.
    - Per Texture Displacement Multiplier
    - Per Tile Global Displace Multiplier
    - Per Tile Global UV1 & UV2 Scaling

    Planned Features:
    - Per Vertex Displacement Multiplier
    - Per Texture UV Scaling


     
    StephenL likes this.
  23. Zymes

    Zymes

    Joined:
    Feb 8, 2017
    Posts:
    118
    This will definately be a Spintires killer if you play your cards right. Mod support for vehicles AND maps integrated into the game with multiplayer and you have a gold selling game. Maybe even add avatar support so you can enter/exit vehicles and repair parts that break and apply winching etc.
     
  24. tri-stratos

    tri-stratos

    Joined:
    Jan 29, 2013
    Posts:
    152
    Is this product for sale ?
    If not yet, will it be ? When ?/How much would it cost ?
     
  25. Shadow-X6

    Shadow-X6

    Joined:
    Apr 29, 2016
    Posts:
    108
    Hi
    You will create Tutorial How setup TrussPhysics fro Vehicles ?
    Thanks :)
     
  26. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Just my input: I think you can search for and look at the source code for the red car demo..
     
  27. Shadow-X6

    Shadow-X6

    Joined:
    Apr 29, 2016
    Posts:
    108
    I did not find a tutorial and I do not even have a RedCar project from HearthBroken :)
     
  28. DevilRat

    DevilRat

    Joined:
    Mar 13, 2018
    Posts:
    1
    Is this still an ongoing thing? Everything I need for my project is in this thread.
     
  29. ASDev

    ASDev

    Joined:
    Dec 9, 2012
    Posts:
    48
    Hi!
    Did you use TxSoftBody for rims or something else? I can't setup non-deformable truss bodies in TrussPhysics ^(
     
  30. Zeeshan-Butt

    Zeeshan-Butt

    Joined:
    Jun 25, 2014
    Posts:
    2
    you want to sell it ?
     
  31. Natsugo99

    Natsugo99

    Joined:
    Oct 31, 2019
    Posts:
    3
    are you gonna sell this in the assets store?