anedumgottil / VR-Mazmorra

Procedurally generated VR Dungeon
Apache License 2.0
1 stars 0 forks source link

Create a Technofog Grenade #28

Closed apodgo2 closed 6 years ago

apodgo2 commented 6 years ago

See #10 :

The Player should be able to pick up items and drop them, and throw them by consequence.

This is already for the most part ready to go thanks to the new integration of VRTK in 692c9e871bdff02d3a346730ddbb5147a1ae3ba7. This means we can get started on some cool items to add.

The first item I want to add is the Technofog Grenade which will be activated, then thrown by the player. And after a short time, it will spew out some pixelated Technofog (done by creating Microblocks around it) which will disrupt the Turret's ability to see the player (it will prevent the targetting raycast from working). The Technofog will disappear over time which may mean we'll need to create a new MicroBlock class. The grenade will then delete itself or change to a spent version of itself.

apodgo2 commented 6 years ago

The Technofog Grenade works entirely as intended as of the Beta release. You can see the squashed commits here: 108970edae9398309e5dd4dd567564964c81d08d

It has a blinking light and a beeping noise, as well as a timer that's based on it's Entity health attribute, so that you can set the time of the grenade by adjusting the health of the grenade! And since it die()s to create the cloud as a death animation, the grenade can actually be shot to bypass the timer entirely.

Activate the grenade with trigger, grab with grip button. VRTK has set it up as a throwable object, so your throwing movements/velocities will be exaggerated to make it easier.

I got around the problem of creating Technofog MicroBlocks by simply making a component script that can be attached to MicroBlocks by a Block function, which will make them into Technofog MBs. It basically makes them into objects that decay over time, by setting their renderer material shader alpha value progressively lower until it reaches 0, at which case it kills itself. It also makes the entire MicroBlock into a VRTK_InteractableObject, which means this has a TON of overhead - and it's not a good idea to generate massive volumes of Technofog. It does this so it can be touched by the controller to be removed. I would have used a collider and a RigidBody activator whatnot from VRTK, but I didn't have time. And in fact, moving to a flat collider/rigidbody or whatever and just using a trigger to remove the block if anything enters it, would be much better than the current setup. And probably should be moved towards once we give ourselves the ability to generate custom MicroBlocks (we might need to pull them in with MapLoader even. Should be easily done with the new MapLoader states)

The creation of the Technofog component is done with a new function in Block: https://github.com/Anedumgottil/VR-Mazmorra/blob/108970edae9398309e5dd4dd567564964c81d08d/Technodungeon/Assets/Scripts/Block.cs#L112-L129 I tried to make a straight up generic Component addition function, but it was not possible because the Block function exists in the .NET Mono namespace/encoding and not the UnityEngine one, and thusly, we cannot pass Component Types to a Block and have it apply it to the MicroBlocks for us. Which means we'd either need to iterate over each MicroBlock and add it ourselves (not good for encapsulation) or generate the MicroBlocks with the component from the beginning using Block constructors and functions as part of the generation of Blocks (better, but requires custom MicroBlocks).