Giter Club home page Giter Club logo

randomation-vehicle-physics's Introduction

Randomation Vehicle Physics

This is a vehicle physics system for the Unity engine, originally developed with Unity 5.6. The most recent Unity version it has been tested with is 2019.2.9. It aims to achieve semi-realistic, general-purpose driving mechanics. This was originally sold on the asset store as Randomation Vehicle Physics 2.0.

How To Use

Documentation can be found in the manual.

Import the repository into the top level of a blank Unity project folder to make sure everything works. After that, you can attempt to import it into your own project, but be mindful when merging the project settings. Read the section of the manual about project settings to make sure you copy the ones that are important and address potential conflicts with your own project settings.

Contributing

You may contribute by first pulling the repository into your own fork where you can add commits, then creating a pull request to merge your changes. After a pull request is approved, it can be merged into the master branch.

If you feel up to it, you can try tackling one of the issues in the issues tab above. You are free to put comments around your code giving yourself credit if you feel compelled to do so. If you add new properties/variables when contributing, make sure their default values do not change the behavior of the included prefabs. Any added code will be considered to be under the MIT License as the rest of the repository is.

Which Branch?

You will want to pull from the master branch, not Master-Old. This is because back when I initially created the repository I was learning how to use Git and the repository started out with a messy commit history, so later on I chose to rebase the older commits into a single initial commit. The old history is still present in Master-Old while master is cleaner. However this means that the two branches have incompatible histories, so if you originally pulled from Master-Old you may not be able to fetch newer changes in the master branch. For the forseeable future, master is the official branch and the only one that new changes will be pushed to.

License Info

Code is licensed under the MIT License. You can sell projects that use code from this repository as long as the MIT License is included with indications that it applies to the original code here. Valid commercial projects include compiled applications and/or "assets" containing uncompiled source code. As long as the code from this repository is not being sold by itself, what is being sold is most likely permissable. Basically, it must include substantial modifications and/or additions.

All models and textures are public domain and were created for this package.

Font:

Roboto under the Apache license http://www.google.com/fonts/specimen/Roboto http://www.apache.org/licenses/LICENSE-2.0.html

Sounds are from freesound.org, some of which are public domain, others are under either the Creative Commons Attribution license or the Creative Commons Sampling Plus license.

http://creativecommons.org/publicdomain/zero/1.0/ http://creativecommons.org/licenses/by/3.0/ http://creativecommons.org/licenses/sampling+/1.0/

Sound links:

Engine: http://www.freesound.org/people/cr4sht3st/sounds/157144/

Hover Engine: http://freesound.org/people/larval1977/sounds/38488/

Boost: http://www.freesound.org/people/pengo_au/sounds/90143/ http://www.freesound.org/people/ftpalad/sounds/119902/ http://www.freesound.org/people/snakebarney/sounds/138101/

Hover Boost: http://freesound.org/people/LG/sounds/14585/ http://freesound.org/people/ejfortin/sounds/49693/ http://freesound.org/people/vrodge/sounds/119499/

Tire Screech: http://www.freesound.org/people/audible-edge/sounds/71739/ http://www.freesound.org/people/audible-edge/sounds/71738/ http://www.freesound.org/people/audible-edge/sounds/71737/ http://www.freesound.org/people/audible-edge/sounds/71736/

Collisions: http://www.freesound.org/people/Halleck/sounds/121622/ http://www.freesound.org/people/Halleck/sounds/121656/ http://www.freesound.org/people/Halleck/sounds/121658/ http://www.freesound.org/people/Halleck/sounds/121623/ http://www.freesound.org/people/Halleck/sounds/121657/

Tire Pop: http://www.freesound.org/people/Gniffelbaf/sounds/82121/

Rim Collision: http://www.freesound.org/people/dheming/sounds/177781/

Rim Scrape: http://www.freesound.org/people/UncleSigmund/sounds/30640/

Tire Air: http://freesound.org/people/Adam_N/sounds/164623/

Glass Break: http://freesound.org/people/m1a2t3z4/sounds/112213/

randomation-vehicle-physics's People

Contributors

justinvoke avatar ramzis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

randomation-vehicle-physics's Issues

Vehicle on last gear accelerates as fast as first gear.

Hello,
First, thank you for this project! It's absolutely amazing.

My only issue I've got so far and am not sure how to solve is :
If a vehicle starts on its last gear (6th gear for example), the vehicle will accelerate as fast as if the vehicle was on 1st gear.

Making shifting up and down meaningless as it just limits the RPM but maybe not the torque?

I was expecting that the car accelerates very slowly in 6th gear, then the more you downshift, the more acceleration the car gets until it reaches a certain RPM ?

I was wondering if it is a change that has to be done in DriveForce.cs but I am really unsure how to do that properly hence why I'm reporting this here hoping for any help!

Thank you so much!

Allow Customization of How Suspension Compression Affects Wheel Friction

Currently, a wheel gains friction as its suspension is compressed, but this relationship is hard-coded into the ApplyFriction method of the Wheel script. This should be adjustable with a simple property in the inspector.

The default value of the new property should cause no changes to current vehicle behavior.

Forward wheels rotation when drift

When car drifting, in the real world, the forward wheels rotation will be rotate follow car moving direction, but in RVP, forward wheels rotation not like that. Could improve this thing which look like real drift behaviour ?

Please provide all steering modes , button,tilt and steering wheel mode...

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Better Behavior of Automatic Gearbox Transmission During Wheel Free Spin

As it stands, the automatic gearbox transmission doesn't perform optimally when engine torque is increased enough that wheels lose grip and spin freely while accelerating. The transmission will respond to the quickly rotating wheels by upshifting and reducing the torque output to the wheels. However, this also leads it to respond again by downshifting, because now the wheels are not spinning as fast. This creates an infinite cycle of upshifting and downshifting without the vehicle ever being able to gain speed.

There is a way around this with the help of the "feedback RPM bias" variable on the Wheel script, but it feels a bit kludgy. This variable modifies the feedback RPMs sent to the transmission by interpolating them with the velocity of the wheel object, rather than its rotation rate. It creates more stable behavior, but it would be better if the transmission could handle the issue by itself.

(Feedback RPMs are send backwards up the drivetrain from the wheels for the sake of controlling engine and transmission behavior.)

Create Method for Saving and Loading Presets

It is not easy to transfer certain properties between different instances of the same components or implement a vehicle customization system in a game. Being able to save and load presets for different components such as suspensions, transmissions, engines, wheels, and other parts would make it much easier to manage a project with many vehicles and allow them to be customized.

ScriptableObjects could potentially work for serializing properties. Perhaps customizable classes could use an interface implementing methods for saving and loading presets. Some components might need multiple groups of customizable properties, such as a wheel having a group of properties for tire friction and another one for tire size or audio clips. Users might want to maintain the same friction preset for wheels on vehicles, but load different presets for the sizes of the wheels and vice versa.

For easy drift behaviour

Hi RandomationGames,

I want to make easy drift function but want to car stable, too. So how i can config the vehicle ?

Thanks in advanced.

Engine Audio Pitch Fluctuates When Rotating in Air

The pitch of the engine audio of a vehicle is lower when moving backwards through the air compared to when moving forward. This is most noticeable when stunt mode is enabled in the demo scene and you rotate laterally in the air while holding the throttle.

This issue is present on both gearbox and continuous transmission types, but disappears when auto shifting is disabled on the gearbox type. This leads me to believe it is related to the transmission classes, but I haven't been able to find the source of the problem.

HUD Breaks

Its me again. Sry, but whenever I edited the Menu just to rearrange the buttons, the HUD stopped working and various parts of the car no longer worked, like the automatic shift. Plz help, because this has happened alot. P.S. i fixed my previous issue

Add Support for Continuous Tracks

This would allow for the simulation of tanks and industrial vehicles using continuous tracks/treads. This could require extensive refactoring of wheel and suspension scripts. New scripts will have to be written for the sake of handling tread meshes.

Custom Map Issues

I loaded into a custom map, and made a terrain. I grabbed the F1 car prefab, applied all of the scripts, but what I get is a car that has wheels moving, but no motion. Plz help

Calculate Tangents for Tire Marks

Calculating tangents for tire mark meshes would allow for them to use materials with normal maps. This is useful for mud/snow tracks where they should appear to leave a impressions in the surface.

Tire marks are generated in the TireMarkCreate script. The tangent arrays should be handled similarly to the others such as vertex and uv.

Vehicle hovering above ground, cant drive

In both demo scenes, no matter which vehicle i use, it hovers above the ground and I cant drive. Manually lowering it to the ground causes contact of the wheels, when accelerating the speed meter goes up as well, MPH stays at zero and the vehicle wont drive. The project only contains this repo (Unity 2022).

Normalized Torque Curve for Gas Motor

Currently, the torque curve on the GasMotor script represents both the RPM range and the torque of the engine across the range. This means that the top speed of a vehicle is directly impacted by the width of the curve. The problem with this is that it's difficult to change the top speed of a vehicle while maintaining the same torque levels across the RPM range.

I have contemplated adding an option for the torque curve to be normalized with regard to its RPM range. With this, a separate variable could be used to set the maximum RPM of the engine while the torque curve remains unchanged. The torque curve will be sampled at a normalized point based on the current output RPM of the engine relative to its maximum RPM.

Basically, the x-values of the torque curve will range from 0 to 1, and the sampled value in this range will be the fraction of the engine's current RPM out of the maximum RPM.

More Metal Like Deforms on Meshes

This is a really great project and i personally thank all who contributed.

What really improves this project is that having more metal like deformations. Like in Truss Physics:
https://www.youtube.com/watch?v=fNfChjsYLXc

I'm working on this project for my more damage based game. I'm planning to have not only crashes, also other flying objects' impacts.

Deformation takes a lot of CPU power (have 200ish mesh colliders & no collider deform) and deformation itself can be improved with more realistic way. Instead of checking all the vertices, can we handle vertices as groups with their neighbour vertices and bend object itself with predefined specific points. Displacement parts is just avoiding this realism so i put that off topic.

For example, instead of making deforming the hood with impact, we can bend the whole hood with predefined vertex points. Here is a basic bending code:

       vertices = mesh.vertices;
       //We're bending around the x axis for example but it depends on force and direction.
        if (axis == BendAxis.X)
        {
            float meshWidth = mesh.bounds.size.z;
            for (var i = 0; i < vertices.Length; i++)
            {
                float formPos = Mathf.Lerp(meshWidth / 2, -meshWidth / 2, fromPosition);
                float zeroPos = vertices[i].z + formPos;
                float rotateValue = (-rotate / 2) * (zeroPos / meshWidth);

                zeroPos -= 2 * vertices[i].x * Mathf.Cos((90 - rotateValue) * Mathf.Deg2Rad);

                vertices[i].x += zeroPos * Mathf.Sin(rotateValue * Mathf.Deg2Rad);
                vertices[i].z = zeroPos * Mathf.Cos(rotateValue * Mathf.Deg2Rad) - formPos;
            }
        }
        mesh.vertices = vertices;
        mesh.RecalculateBounds();

So maybe we can improve this and integrate with predefined point inputs per object for more pleasing damage physics with metal feel. What do you think?

Rigidbody Mass Doesn't Affect The Drive Force

I found this issue when i was changing the vehicle rigidbody mass to a large value. The vehicle keeps moving fast.

and i found this code in Wheel.cs:
rb.AddForceAtPosition(frictionForce, forceApplicationPoint, ForceMode.Acceleration);

change to"
rb.AddForceAtPosition(frictionForce, forceApplicationPoint, ForceMode.Force);

For the best result, make a member variable ForceMode globalForceMode; in Vehicle parent, and replace all ForceMode.Acceleration to vp.globalForceMode. It will also affect the suspension behavior that was previously doesn't respond any rigidbody mass changes.

Need Assistance, Tractor Rollover

Hi i am new to RVP and need assistance. I just configure my vehicle(Tractor). But it rollover very quickly as i move left right with some speed.
Which value i should change? Check attached gif
issue

Thanks

Improve car sound engine

Hi,
I think car sound engine now is very simple or poor. Its not real. I think we must to improve this feature, because its very important, i think.
You could referent to this audio plugin for unity 3d, its really cool and real.
http://www.crankcaseaudio.com

Input system support

Is your feature request related to a problem? Please describe.
No, I just want some directions to make a pull request in a new branch with Input System support

Describe the solution you'd like
I changed the input handling and made some features for using it as default Input.

Describe alternatives you've considered
N.A

Additional context
Hi, I'm pretty new into open source development, just worked with git in groups some time ago. I would like to receive some directions about how can I make pull request in a safe way. I've just finished a version with the Input System package for Unity in top of this repo and want to share with anyone so if their project uses it, they don't need to do by theirself. Also I'm creating some brand new features into the physics system and user accessibility to the features using Unity Editor Windows as I will use in a project and really want to share all of this stuff for help everyone that want it as well the repo owner helped me to undertand some physics reading this code.

Networking Support

The package should be refactored to support easy networking integration with something like Photon or Unity's Networking.

Cast tyre collision

I want to recreate with the raycast the motorcycle tire.
Multiple raycast in 3d direction or similar result.
Thanks for your help.

Low-Friction Surfaces Should Cause Wheels to Slip More Readily

Right now, traction control is an unavoidable side effect of the way wheel drive is applied in relation to wheel and ground friction. This means that wheels will not spin freely on slippery surfaces regardless of the acceleration input (unless the torque is very high, but this will happen even on surfaces with friction). This is also noticeable when tires are blown out, where driving on rims should yield more slippage under maximum acceleration, but instead the wheels spin slowly enough to not slip at all, making it seem like the vehicle isn't "trying" to accelerate.

The Wheel script's method of setting it's final rotation rate should pay attention to the friction of both the ground surface and itself, and be able to react either by spinning freely or maintaining traction control based on properties in the inspector. Default values of new properties should not affect current behavior.

Ai adds instanced physics materials to other objects

Ai changes the physics materials set in scene.
Which fights with our objects setting specific physics materials in code in order to achieve different outcomes.As a result playmaker cannot get the new Instanced physics materials or set them to work with our custom physics.Which results in both physics fighting of setting different physics materials.So as the ai is driving on different objects in terrain and road we can no longer get these physics materials and set them.

Hi, there your control is very impressive.

Hi, there your control is very impressive.
Just want to share a view about project hierarchy management. Isn't it better to place all folders in single folder with name of RandomationVehiclePhysics folder. Just for us(users) as we have own things as well in project. It might get messy.
Also i am making mobile game. So will looking forward to add Left/Right Buttons & Steering wheel functionality.
Regards
Muhammad Waqas

Thick Wheel Collisions

Wheel collisions are currently done using raycasts. This does not work so well when driving across complex geometry or driving vehicles with large tires. A method for testing wheel collisions using cylinder approximations would be ideal. I have tried using SphereCasts a bit in the past without success.

Performance is crucial and the wheel collisions must operate in a similar manner as the GetWheelContact method of the Wheel script. It would also be interesting if the wheel collisions could react appropriately to contact points that are on the top or sides of a wheel. Those cases are complex because they should not compress the suspension, but still provide some kind of pushback and traction.

Script Execution Order And Roadmap

Hi,

Thank you for the great project!

Is there any way to optimize the logic architecture and remove the execution order?

Is there any roadmap for future development?

Thanks again!

What determines the position of the main camera ?

Im trying to create my own vehicle using modified prefab and so far so good car moves and steers but camera always point underneath the chassis, Ive tried modifying the parameters of height and distance but it always was either too far or too low .

Decreasing the number of Fixed Timesteps causes the vehicle to jump finely

I don't know the cause, but as the title says.
Validated to reduce to save CPU because too many initial values.
If me reduce it a little, a small amount of shaking will occur.
Reduce it in half and the vehicle will start to jump
Will not stay still properly.
This also happened when trying to port Rigidbody's AddForce to Jobsystem Update to speed things up (due to structure, probably skipping some frames).
What approach can I make them lighter?
Is there any way to reduce the number of Rigidbody AddForce?

I feel this asset is great and I'm creating more realistic vehicle behavior while customizing it from the era of Asset Store.
I don't want to consider stopping using this asset whenever possible.
Please give me an idea.

Damage Should Create Paint Scratches

The VehicleDamage script only takes care of deforming meshes and detaching parts of vehicles. It should scratch the paint too. I haven't been able to think of a good way to go about this, beyond perhaps using a method similar to the way tire marks are created.

The scratch generations must be handled with care as to not lead to excessive garbage collection.


Another idea I got from a comment on a YouTube on a video about car damage in Unity is to use the vertex colors as a mask to reveal a texture containing scratches. The vertices that are displaced in a collision could have their colors changed. This method would also require a custom shader.

Each channel of the vertex color could correspond to a unique texture representing the direction of the scratches. For example, you could have vertical and horizontal paint scratch textures on the material, corresponding to the U and V directions in texture space. The R and G or B values of the vertex colors could be linked to each of the textures, and the shader could blend between the scratch textures based on the colors. Upon collision, the relative velocity of the impact could somehow be transformed into texture space/UV coordinates and stored in the RG values of the colors.

Improve Gear Distribution of Gearbox Transmissions

The auto-calculated RPM ranges for gearbox transmissions have a bias towards lower speeds, leaving much of the vehicle's speed range for the highest gear. This is most noticeable with fast vehicles.

The calculation is performed in the CalculateRpmRanges method of the GearboxTransmission script.

Namespaces for All Scripts?

I am considering wrapping all of the scripts in the namespace "RVP" for smoother integration into projects.

Car not stop when moving forward

When car moving forward that accel = 0, car will infinity moving with same velocity if car go forward, not go right or left...just go forward. Car never stop. Please check this bug.

Improve Two-Wheel and Single-Wheel Balance

The VehicleBalance script is unstable, making bike and monowheel physics unsuitable for a proper game. Bikes should be able to steer and lean predictably without falling over as well as pull off wheelies/endos. Monowheels should be able to stay upright and turn on the spot. Both vehicle types also need to handle landing after catching air.

The physics should aim for balance through the AddForce and AddTorque functions or other similar methods. "Cheating" methods such as moving the center of mass below the ground should be avoided because they can lead to other undesirable behaviors.

RPM is Not Actually Rotations Per Minute

This is due to a mistake I made early on in development. I was basically equating "rotation rate of wheel" with "RPM" and not consciously thinking about what RPM really means. I did not realize this until long after the initial release was finished (back when this was sold as a Unity asset). Unfortunately the entire drivetrain is riddled with variables falsely referring to rotation rates as RPMs. The calculations in the scripts and the prefabs' variables depend on the way things are currently set up, so nothing is going to change.

This issue is for the sake of letting people know in case they are depending on RPM actually being rotations per minute. This package was never intended for proper physically accurate simulations anyways.

RPM in the scripts is roughly equal to rotations per second multiplied by 314. This can be found in the GetRawRPM method of the Wheel script:
rawRPM = (contactPoint.relativeVelocity.x / circumference) * (Mathf.PI * 100);
Raw RPM is what the rotation rate of the wheel would be purely based on its current velocity and circumference. Part of what led me to make this mistake was focusing on the rotation of the visual representation of the wheel.

A game object can only be in one layer error?

From console log:

A game object can only be in one layer. The layer needs to be in the range [0...31]
UnityEngine.GameObject:set_layer(Int32)
RVP.Wheel:Start() (at Assets/RVPassets/Scripts/Drivetrain/Wheel.cs:268)

how to control the vehicle

I don't how to control the vehicle. So please tell me what did i do wrong. I can't use every vehicles and demo scene.

Stop AI car if next waypoint is not available

Can you modify the Follow AI script to include a conditional check for reaching the designated waypoint. Once the waypoint is reached, trigger a stop command or initiate a controlled deceleration process to ensure the vehicle halts smoothly and without errors. Integrating this functionality with a navigation system can further enhance accuracy and reliability in autonomous navigation tasks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.