Search Unity

How to achive this type of arcade car physics?

Discussion in 'Scripting' started by Paulx774, Sep 8, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    EDIT: It looks like this thread doesn't go anywhere. It's a bit complex. I'll have to figure it out by myself.
     
    Last edited: Sep 15, 2021
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    some guesses:
    could be just a raycast or few of them, and then align car to surface using those (and of course raycast wont get stuck, car would always be above the surface),
    or just a lower resolution ground collider (compared to visual terrain itself),
    and/or ground collider doesn't collider with bumper collider.
     
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Holistic3D has done a good tutorial on car physics you should probably look at and it will help you get some decent driving mechanics started, you'll need to do a lot of studying. It takes a good understanding of car physics generally to even get that arcadey feel.

     
  4. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    My guess is that the car has one box collider. Because, when they are upside down, the car doesn't tilt. You can also collide with your opponents in the game, so I guess, the box collider covers the entire car.

    I thought the same things you wrote, but there are some issues.
    - If the car doesn't collide with the landscape, a lag can cause the car to go through the map. Even with low FPS, I've never had that issue in this game.
    - If the car doesn't collide with the landscape, the raycast(s) will not detect the ground. Imagine the car is going toward a ramp. The front of the car will overlap with the ramp and if you use raycast from the wheels, it will never detect the ground. If the car collides with the landscape, the car will crash the ramp before raycast(s) detect the ramp.

    I'm almost out of ideas about how to do this.
     
  5. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    This one is more like simulation/arcade style. I made car physics before but I'm looking for a car physics like in that game. As it can be seen from the video, the car's rotation snaps as it goes toward ramps, slopes etc. I don't think, there's any logic like suspensions, wheel collider etc.
     
  6. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    In that case you'll probably want to look at how to use raycasts to interact with the ground look up tutorials on ground alignment. Often the trick is to raycast to the normal and align your gameobject with that, this will take some tweaking though to make it work with your car physics naturally.



    Just something of a caveat though, I'm not really a huge fan of this as often there are issues with static or solid objects. You can see even in this example with a basic cube that because the object is just blanketing itself on the ground very often there are gaps between the cube and the surface it is aligning with. Hell if you look at Fallout 4 for example and their building system, this is an incredibly common problem when it comes to even slightly uneven terrain.

    This is why I think more advanced driving simulators for example make good use of individual tires and rocking physics so the car actually looks connected to the surface even if it is incredibly bumpy and uneven.
     
    Last edited: Sep 8, 2021
    Paulx774 likes this.
  7. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    That's exactly what I'm looking for. I always thought using 4 raycasts from the wheels and doing something with the hit normals, but I didn't know how to get average of those normals. The magic line of code is:

    Code (CSharp):
    1. Vector3 newUp = (hit.normal + hit2.normal + hit3.normal + hit4.normal).normalized;
    The only problem that is left is to move the car. In the video, he uses the character movement to move the box, in my case it will be a car. So, a force/impulse needs to be applied. How can I move the collision box on the ground without hitting the landscape?
     
  8. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    You could adjust the collision box in runtime as it changes rotation or move it up a bit more so when it rotates with the car it's less of an issue? Like I pointed out it's probably going to take some tweaking either way, you'll have to figure out what works best for your particular use case.

    For example you could do a check to see what angle the car is rotated at and have some pre-configured settings for the collider to change to when that happens.
     
  9. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    Even on the flat surface, the box will hit the ground, I guess. Also, tweaking its transform may cause some problems in terms of physics. For example; when the players hit each other, they might overlap each other.

    Anyway, I'll try some things and share the result here. Thank you.
     
    Lethn likes this.
  10. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Yeah, it's a balancing act, you just have to find what you can bear with and what works for your project.
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    whats the name of that game?