[4] - VR Space Combat - Entity Table

After my final year of University concluded and prior to returning the Oculus Quest headset on loan, I created a project to utilise the Oculus Quest controller as a joystick. This used the rotation of the controller to direct a plane’s pitch, roll and yaw. I initially had it fly the plane as if it were an RC plane and later attached the player character to it. It was a lot of fun for me, but for anyone else it was a sickening experience due to the not-so intuitive controls and motion-sickness.

Fast-forward to a few months ago and re-acquiring a Quest headset, I redrafted my project idea to create a Space Fighter game where a player could engage in space combat. I took inspiration from games that included small and large scale space combat such as Stellaris and Star Wars with their behemoth spaceships but most notably Halo with their holographic tables - leading me into the idea of an interactive table that a player could control a gigantic ship and visualise the battlemap.

Entity Visualisation

The goal was to be able to display an entity such as another ship on the table approximate to its world-space positioning, and angle from the ship the entity table is linked to.

I created the table with a 3D box, added a table-top box and cylinder to visualise the radius that the ship detects other entities - in this case other ships.

Image 1: Empty Entity Table

Next was to take entities (in this case ships) and place a reference to them on the map. For this I initially set some variables I would check against to ensure an entity was within the confines of the parent ship’s view.

tableWidth = table.transform.localScale.x; tableLength = table.transform.localScale.z; gridWidth = tableWidth * defaultGridScale; gridLength = tableLength * defaultGridScale; gridCenter = shipParent.transform.position;

After this, it was a case of ensuring the entity’s position was within the confines of the grid’s minimum and maximum width and length, and updating its position on the table.

The limitation of doing this was that were the ship to rotate on its yaw and face a different direction, the 1:1 world-to-grid would no longer be exact. As such I moved onto acquiring an entity’s position based on direction from the parent ship to the entity, and distance between the entity and the parent ship. If that distance was within half the grid’s width, the entity would be displayed on the map.

I have split the code to display each entity in adjacent to the parent ship in three parts. The code in its entirety was ran each frame, for each entity if the distance was within the grid’s width:

1. Acquiring distance and direction (in this regard is rotation)

float distance = Vector3.Distance(ships[i].transform.position, shipParent.transform.position); Vector3 relativePos = ships[i].transform.position - shipParent.transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.down);

2. Setting the position on the map based on the distance and direction of the parent ship

float distanceScaled = distance / defaultGridScale; Vector3 newPosition = (rotation * shipParent.transform.forward) * distanceScaled; newPosition = new Vector3(newPosition.x, HoloTableships[i].transform.localPosition.y, newPosition.z); HoloTableships[i].transform.localPosition = new Vector3(newPosition.x, newPosition.y, newPosition.z);

3. Setting the rotation depending on the parent ship’s current rotation

Quaternion addedRot = ships[i].transform.rotation * Quaternion.Inverse(shipParent.transform.rotation); HoloTableships[i].transform.rotation = addedRot;

The end result is a table that shows other entities based on the direction of the parent. I further added material changing of the ship visualisations based on checking whether the ship is an ally or enemy.

At the above of this post I have included a video of the table in action.

VRSpace1.png

Future

Things to work on regarding the entity table in the future:

  • Globe mode - a friend suggested having a setting for visualising the entities inside a globe as oppose to a plane

  • Text description above entity - further information such as threat level, stance and damage status in hovering windows that could be toggleable

  • Better models to represent entities and the table - with the current models merely a cube and another rotated cube, having better models to represent the varying sizes of ships that will feature on the battle map will look much better than a one-for-all entity

  • Holographics - I intend to add the Lightweight rendering pipeline to the project after changing the project to support VR. As the project currently uses a Windows voice recognition library I am unsure yet how to go about changing that to cater for an Android build.

Previous
Previous

[5] - Patterns Out Now!

Next
Next

[3] Patterns - Streak System