Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How would you implement a car drifting arcade game mechanic?

Discussion in 'General Discussion' started by iko, Jul 28, 2023.

  1. iko

    iko

    Joined:
    Mar 19, 2014
    Posts:
    9
    Hello,

    For personal exercise I'm trying to replicate the control mechanic of the "Hot Slide" mobile game:


    My idea was that the car oriented its forward according to the position that the player chooses with his virtual joypad. Car goes straight on in this direction.

    The problem arises when I try to imagine how the "drifting" effect could be implemented when the forward of the car suddenly changes.
    The car skids with the rear axle and has some inertia.
    I assume it can be solved with a fairly basic vector math but that I can't set up.

    Please can anyone help me?

    Thank you
    Fred
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,028
    Just a hint: there's at least one arcade car controller with sliding mechanics on the asset store that's free. I believe it implements one of the popular concepts, there are also tutorials about these arcade drift mechanics and how to implement them.
     
    DragonCoder likes this.
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    I think that's a rather unusual control for a racing game. Because car cannot go straight to a direction. It can go forward and backward and steer. Normal control for a car even in 2d is "steer", "accelerate", "brake". And those handle drifting just fine.

    So with your chosen scheme, when user presses a direction, your car will have to decide how to control steering wheel in order start moving in direction the player wants. And that can make the game quite difficult.

    Now, you CAN implement drifting in this control scheme, basically use the same thing as when you're using "steer, accelerate brake scheme". When force pushing the car sideways becomes too high, the excessive force will cause it to accelerate and that will cause steering.
     
  4. iko

    iko

    Joined:
    Mar 19, 2014
    Posts:
    9
    Thank you for your kind reply.
    I haven't actually found any serious tutorials on how to implement a drift mechanic in unity.
    If you have links can you share them? Thank you
     

    Attached Files:

  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    Well, "inertia" is the tendency for a body to remain in its current state. For the purposes of a driving game, that means that in the absence of external forces it will continue moving in the direction it is currently moving in.

    "Drifting" is when the car is moving in one direction while pointing in another.

    So essentially what you want is for the car to rotate more quickly than its inertia changes direction. It's arcadey, so you don't need to worry about accurate physics for the rotation, so I'd just start by giving my "cars" (they would not be implemented like real cars at all) both a high inertia and a high rotation speed, and just smoothly rotating them towards the input direction.

    I know that the objects in that video look like cars, but they behave like Mario running over ice. Don't try to simulate cars and/or racing controls here, it's a red herring.

    The "drift" part is a combination of tuning your vehicle / character controller, and using a vector dot product to compare an object's forward direction to it's velocity.
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    Actually you can probably do that and it will even feel right.

    A wheel is a directional constraint that can cancel specific amount of force directed perpendicular to the wheel. The thing is, amount of force is limited by traction.
    Now, when car turns, centrifugal force is applied (if you want to keep it simple), or torque is applied (if you don't want to).

    So you can calculate the moment when the the force surpasses wheel's ability to cancel it, that's when the car begins to drift.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    Aye, but that's far more complicated than what's on show in the reference video.
     
  8. halfawake01

    halfawake01

    Joined:
    Jul 19, 2023
    Posts:
    4
    It's awesome that you're working on replicating the drifting mechanic from "Hot Slide" for your own arcade game. Implementing drifting in your game can definitely be achieved with some vector math magic.

    To create the drifting effect, you'll need to handle the car's orientation and movement in a way that simulates the skidding and inertia. One approach is to calculate the car's velocity vector based on the chosen direction from the virtual joypad, and then introduce a separate drift vector that influences the car's movement during the skid. This way, the car's forward direction can smoothly change while still maintaining some inertia and sliding action.

    Remember, it might take a bit of trial and error to fine-tune the mechanic and get it feeling just right, but don't be discouraged! Keep experimenting, and with a bit of persistence, you'll nail that awesome drifting feeling.
     
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    This sounds a lot like ChatGPT text....
     
    Ruslank100, m0nsky, stain2319 and 2 others like this.