Search Unity

Anti-Gravity Hovercraft Racing (Physics)

Discussion in 'Scripting' started by waheeda, Jul 14, 2014.

  1. waheeda

    waheeda

    Joined:
    Jul 14, 2014
    Posts:
    1
    Hi,

    I am working on a wipe-out like anti-gravity racing game, i need to know what would be the good approach

    1. should I use transform.rotate and transform.translate for moving the hovercraft ( I have a working solution for this but that needs to be improved)
    2. or should I go with the natural physics (I worked on this too by applying upward and downward forces, but on collisions, vehicle goes out of control, and i have no clue how to make it stable) Please suggest and any help with the script and physics will be greatly appreciated.
    Thanks,
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    1. I prefer Vector3.MoveTowards and transform.LookAt()

    2. You need to add an upward force as soon as the craft height goes below a certain point due to gravity. Use a random value for the point to make it look like it is hovering. You can use raycast to determine the height of the craft in relation to the terrain.

    3. If collisions make it go out of control, adjust the mass on the rigidbody.
     
  3. Deleted User

    Deleted User

    Guest

    This is a very interesting question because I am having the same block too. I've dumped a track from Mario Kart 8, and I planned to use it in a playable demo of MK8 with the Unity Engine. i just need the right method to emulate anti-gravity racing.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Making something hover, whether you use the physics engine or your own custom physics, isn't as simple as just applying an upward force. To maintain height realistically you need to adjust the force based on how far away you are from the target height, as well as your current upward velocity.

    This is known as a control problem, and there are decades of control theory that boil down to mostly a couple of simple techniques. The most common is known as a PID (Proportional, Integral, Derivative) loop, and I wrote about how to do that in Unity in this blog post.



    Cheers,
    - Joe
     
    xVergilx likes this.
  5. Deleted User

    Deleted User

    Guest

    PID is fun too, because you can implement it one factor at a time. It's just 3 equations on some very simple measurements, velocity, one raycast to get one distance (to the ground) and then some basic clamps here and there, depending how much freedom you want it to have.

    The P I and D of a PID controller each contribute to more accurate response, for a game you likely only need two (one of them is very worried about randomness from real life physics and mechanical tolerance limitations), or a "PD" controller. These are rare in real life for that reason, the only example I could find was for servos.

    Closer to the ground = higher force up (dial force, mass, drag), and it'll be bobbing.
     
  6. Deleted User

    Deleted User

    Guest

    Excellent I add code for my own game. :)
     
    JoeStrout likes this.