Unreal Project Prototyping

 

In Project Gradual, the biggest hurdle that needed to be dealt with was the rotation of the ship. So, early priority centered around creating a prototype to get an idea of what variables we could tweak to get in the right ballpark.

Early on, it was important to create a prototype that would simulate the intended “anti-gravity” look from 90’s-00’s racing games that we used as references like F-Zero and Wipeout. After a lot of iteration and even more balancing, a final algorithm was designed that matched the project’s vision.

How I visualize the way in which it works is to imagine an object in 3D space that is magnetized to the surface of a sphere. Wherever the object travels, it always does so along the surface of the sphere, not unlike somebody walking along a planet’s surface. As it travels, it inherits the rotation of the object it is placed against meaning every time it moves forward, its trajectory for where it is applying its movement changes.

So to accomplish this effect, the ship was designed to support two states, a “grounded” and an “airborne” state.

In the “airborne” state, the ship reacts to gravity as you would expect, falling at an increasing speed until a terminal velocity is reached towards the planet’s surface (or in this case, falling in a direction opposite the world’s up-vector).

The “grounded” state is where it becomes more interesting. In this state, in order to simulate that anti-gravity style previously mentioned, the ship has to always maintain a rotation that is consistently aligned with the track directly underneath it.

This grounded state was achieved in this way:

  1. Gravitational forces are no longer calculated or applied.

  2. A line trace shoots from the base of the ship to a constant fixed distance below it.

  3. The line trace returns a hit normal from the face of the track mesh that has collided with the line trace.

  4. Create a quaternion using the axis angle method by finding the cross product and dot product of the ship axis’ up-vector and the hit actor’s impact normal.

  5. Apply the new rotation amount to the existing rotation through multiplication.

  6. Apply a fixed location offset in the ship axis’ up-vector to maintain distance between the ship and the track.

  7. Interpolate the ship’s mesh’s rotation to the ship axis’ rotation to allow for a smooth transition.

  8. Interpolate the ship’s camera’s rotation in the same way at a slightly slower speed.

In essence, before applying speed in any direction, the ship calculates a new rotation based on the surface that is directly below it and applies that rotation to itself from a fixed distance away from that object. This algorithm worked wonderfully for creating that overall feel we were looking for.

Comments

Popular posts from this blog

A Year Spent Looking at One Room

Dev Diaries 1: Shaders