Sunday, July 17, 2016

[Engineering and Design] Bifrost System



How did we pull off the Bifrost System?


Well this was actually hard at first since we have to think of a way to make the bridge adjust and update its rotation per frame because Matters can be either Rooted, Movable, or Body Parts. At first we decided that the bridge should spawn in between the two matters when they're tagged so we had to use the distance and midpoint formula.


So in the case of the Bifrost System, we have to find a way for the Bridge to spawn in between the two matters but... Due to constant feedback from our adviser and some other testers that were able to play the early builds of Project Einherjar, we decided to make an effect wherein the first tagged Matter will be the spawn point of the Bridge then will be making an effect where it will look like the bridge is going towards a point.  

I can't fully remember what mathematical formula I used in this effect but it has to do something with the ration of the distance between these matters and calculating its target scale for the bridge,  So this calculation is a per frame basis because as mentioned above we're not really sure what the Matter Type is so we have to compute the target scale of the bridge every frame.




Before we even get to the spawning part, the Bifrost system works when you have the Bifrost Bullet.  This bullet can be found in a specified location in the level.  You can switch between different bullets in the game.  So with the use of the Bifrost bullet of course you'll also be able to use the BiFrost System/Ability. 

How this works is simple... When you set the current bullet to the Bifrost Bullet, you'll be able to detect Matters which highlights the object whenever you aim your cross-hair to it.  It will have an outline effect which is pretty much similar to the toon shader concept in Unity.


It's a shader that we made that activates whenever the object detects that the player is aiming towards it.  When the player shoots a bullet to the matter object, it will be releasing a lock on mesh that will indicate that the matter is already tagged.  



The Bifrost requires at least 1 pair of matter being connected and whenever our system detects that a new pair has been generated then it will spawn another bridge between these pair.  So, Yes you can spawn infinite number of Bifrost bridges as long as your Energy can sustain the cost per Bifrost Bullet.  Yes don't worry we have upgrade systems :) 

The most challenging part of doing the multiple spawning of bridges every new pair generated was how to keep track of the LAST object tagged because this last object will be the first object to be used in the succeeding bridges.  So if you're familiar with Linked Lists then this will be our solution.




Here's a video about linked lists if you're interested

So the main concept of this algorithm is that we have a pointer that points to another element in the list and points to another element whenever the bridge successfully spawns itself.  Also I've added a fail safe system that whenever the Matters are not in the same area the pointer will reset itself to the previous pointed element in the array of Matters.
There's also limit wherein when the Bifrost Bridge stays too long it will automatically despawn itself and fades its shader and removes the capacity of the Valkyrie to walk through it.  In this implementation, we're just reversing the process of the computation of the target scale and position of the Bridge and finally inverse all of the data to get this effect wherein the last tagged object will be the first object which the bridge will despawn itself to.
I can't post that much with the implementation of the BiFrost system but this is mainly how the design of the current system is.  Stay tuned for more design and engineering posts from our team!
Hope to see you this week at Incendium!