Search Unity

How to Make Arcade Car Physics?

Discussion in 'Scripting' started by Deleted User, Oct 15, 2019.

  1. Deleted User

    Deleted User

    Guest

    Hello everyone,

    I was wondering how to make a car physics algorithm like NFS Most Wanted 2005? I don't want any code samples or screenshots. I just wonder how to make it, the logic behind it. I tried to make my own custom physics but I came across some problems.

    - I made a suspension script and used a raycast to apply a suspension force onto the car body from the suspension location (AddForceAtPosition). The result wasn't like I wanted. The car was bouncy as if the suspension is soft (no stiffness).
    - When the car goes uphill or jumps from somewhere, the car's collision hits the ground and that collision slows down the car too much (almost stops the car). In other games, the cars continue its movement.
    - The car can get stuck so easily while moving on rough terrain.

    This is the shortest video I found in order to demonstrate the physics I want. As it can be seen from the video, the car looks like sticks on the ground (as if there is no suspensions) and the roads' shapes don't affect the car. (The car doesn't slow down too much when it hits the ground)

    EDIT: At 3:35, the car goes uphill and jumps but the car's movement doesn't change a lot; and at 3:55, the car gets air but the wheels don't extend as if there's no suspension.

     
    Last edited by a moderator: Oct 15, 2019
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Looks spline-based to me. Just have a bunch of splines. Road width is stored per spline point. It's very stable, and an existing technique for old consoles. Jumps are simply accounted for in code. Note the colliders for the track have infinite height, basically you do not leave the current spline, at least for that video as far as I can see.
     
  3. Deleted User

    Deleted User

    Guest

    I'm sorry but I couldn't understand.

    The car is controlled by a player. How can it be spline-based? Also, the game has a free roam feature; so I don't think spline will work. Could you explain this idea a bit more?

    "The colliders for the track", do you mean the walls that shows the direction the player should go to? The game has a free roam feature. When a race is finished, the walls disappear.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    So you want a free roam feature too?
     
  5. Deleted User

    Deleted User

    Guest

    Yes, I want the players to be able to drive their cars in the map freely.
     
  6. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536


    This is 2D but it's not that hard adding an extra dimension to it, i think he even talks about it there, but i watched this a long time ago so i don't remember.


    did you try using the unity wheel system?
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    https://assetstore.unity.com/packages/tools/physics/edy-s-vehicle-physics-403 is the best I've used for arcade physics. I would just be parroting to you what that does otherwise, so I'd suggest you buy that and pick apart the code - or search for edy's posts - basically the magic sauce is in creating stabilizers, code that will load balance between your spring damp forces for each wheel.
     
  8. Deleted User

    Deleted User

    Guest

    I tried the demo, but I'm not looking for realistic physics. Thank you for the suggestion.

    My main problems is collision. The car can easily hit the ground when I tried to jump off a ramp or go uphill and that makes the car slow down too much, even stops the car.

    Another example can be GTA V. The cars in GTA don't slow down that much even though the car you use is super low and close to the ground. Even if they collide with the ground, they don't slow down too much.

    I have been searching this subject for years, and I couldn't find any physics algorithms like the physics algorithm in the video but realistic ones.
     
  9. Deleted User

    Deleted User

    Guest

    I'll watch the video later and try it; but in 2D, the surface (terrain) is flat so the car doesn't collide with the ground. That might not be the thing I'm looking for.

    I tried the wheel system but that's kind of realistic physics.
     
  10. benjaminbcooke

    benjaminbcooke

    Joined:
    Oct 18, 2019
    Posts:
    1
    First Ever trip in France Road: You need to follow these rules

    On the off chance that you are driving in France, you should know the laws and guidelines of that nation. Driving in France is generally a delight for anybody used to the high traffic experienced on all streets in a significant part of the south of England or the Netherlands. While driving in France you should know France has different sorts of avenues, from thin single-track streets, a significant number of which lead through recorded towns and will make you wish that you had discarded your vehicle and continued by walking, too enormous roadways that take into consideration rapid travel.
    All the significant record you need convey:
    On the off chance that you are seeking France for a short visit or you are come to driving in France as an expat. French specialists are very exacting on all drivers conveying the right records and mandatory hardware a full and substantial driver's permit will permit you driving in France When driving.
    Drivers will likewise need evidence of protection and proprietorship (V5C) just as a visa or national recognizable proof card to fulfill the French specialists
    While driving in Spain you may likewise be required to convey an International Driving Permit
    Drivers in right-hand drive autos will likewise need to fit headlamp pillar redirectors to dismiss stunning other street clients.
    Don't keep sans hands and Bluetooth gadgets
    Don't keep speed camera tyrants
    A full and substantial UK driver's permit will enable you to drive in.
    Every one of the punishments and fines:
    While driving in France the most elevated conceivable charge can be 450 Euros. The fixing fine is 135 Euros, in any case, whenever paid in under 15 days they will take 90 Euros, and whenever paid in excess of 45 they take all the less sum.
     
    Last edited: Oct 20, 2019
  11. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    ... what.
     
  12. Deleted User

    Deleted User

    Guest

    I think, I achieved what I wanted by "faking it". (More likely improved).

    I added damping to my suspension code to solve the bouncy problem. I also changed the collision mesh of the car and added capsule and box colliders in front of the car. Box colliders are placed diagonally and a capsule collider is placed in front-middle of the car. I changed the friction values of the physics materials to 0 for both the ground and the car. Now, it works like the physics in the video; but still it feels like something wrong.

    I'll continue to work on the algorithm and try to find a solution.
     
  13. ToruTheRedFox

    ToruTheRedFox

    Joined:
    Dec 22, 2015
    Posts:
    6
    fyi, the collision for the car body itself only takes up the upper half of the car's body so it doesn't get stuck on rough terrain and steep bumps such as curbs, and this can be seen in rare situations where another car (usually a cop) rams you from the bottom while you're flipped on the side