TransWikia.com

AntiGravity Vehicle?

Game Development Asked by roswell on November 2, 2021

I’m making a racing game akin to F-Zero and Mario Kart 8 with AG mechanics. I currently have a vehicle that is a rigidbody with normal gravity pointing down. True to AG games, I want the gravity to always be applied against the surface of the track (e.g. the player will stick to the surface of an upside-down track). I figure I have two options:

  1. Shoot a raycast below the vehicle that returns the normal of the surface. Apply gravity in the direction of that normal.

  2. Have several "checkpoints" that determine the direction of gravity in that area. When inside, the vehicle is affected by that new gravity.

The issue with option #1 is that it may not work if I wanted ramps or airtime. I could possibly extend the raycast down a lot further to get the normal even in the air, but that could lead to a lot of glitches. There’s also the instance that there is no floor below the player. I noticed MK8 even had gliding sections in anti-gravity where you would twist in the air back to normal gravity, which leads me to believe they had something like #2. The issue with #2 however is that it may require a LOT of checkpoints to be manually placed.

I’m wondering if anyone has an idea to some simpler alternative?

One Answer

Your raycasting sensor sounds like a good baseline to build upon.

You can extend this in three ways:

  • Create a layer that's visible to the player and to physics collisions, but invisible to your gravity sensor raycast. Use this layer for any objects that might distract the sensing, or that you want to deliberately exclude from consideration (small bumpy details, ramps, etc)

  • Add "Gravity Hint" objects that are just the opposite: visible to your sensor raycast, but invisible to the player and other systems. Now you can bridge the "empty" sections or anywhere else the sensor needs a helping hand with hidden geometry to control exactly what it does.

  • Add "Gravity Checkpoint" objects that turn off the sensor and switch your vehicle into a different mode (say, using some fixed gravity, or entering "airtime mode", or aligning to a spline they provide, or any other exotic behaviour you need), and switch the vehicle back to its default on the other side. These let you create localized exceptions to the rules, if even hiding and hinting isn't enough to make a particular section work right.

Out of the box, in a vanilla level where none of these items are in play, you get decent baseline behaviour from your raycasting solution.

By judiciously adding these extra elements where you need them, you have the ability to locally tweak and refine that behaviour to the extent that you need to, without burdening yourself with undue amounts of setup/markup just to get the "normal" sections working.

Answered by DMGregory on November 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP