Monday 1 December 2014

Infrared Game Mechanic v0.1

Alrighty,

Now that I got my raycasting working in my other prototype my next step was to get an Infrared mechanic up and running. We intent to use photography in our project (please see Lukes blog post about this here). Since we are planning to use this I had to come up with a way to implement this.

Akshayan had a very good point that we should do it in a non-boiler plated way. To allow the Astronautics department to edit the mechanic if they so required. This was a very good idea and I kept it in the back of my mind. To implement this mechanic I wanted two major things,
  • Get input (via the X360 controller).
  • Change the texture (material really) of all objects that will be affected by the Infrared mechanic.
 Before I bore you to death with my blog post this is what the end result of this mechanic looks like, I attached it to the rotation prototype:



Please note that this is only v0.1 and the textures along with most assets are a placeholder. Thanks Luke for the cool skybox :D

Adding the Scan-mechanic to the X360 controller
The first thing I had to do was bind an 'Infra' preset (I set this up in the inputs menu in the engine) to Axis 3.  This axis was what the two trigger buttons were tied to. Once done I could manipulate the triggers.

I wanted to know what floating values were being assigned to each trigger as both trigger buttons share the same axis. I could have looked this up on the API reference but I felt like experimenting tonight! I added a statement so check if the Input axis values was greater than 0, just to see what happened.

This didn't work as I had hoped as the left trigger was greater than zero and letting go of both triggers was also greater than zero.

So I thought I'd just output whatever values were being assigned to the axis depending on what trigger I held down. And what value was outputting when I had no trigger held. So I added some console prints:

 
Adding Debug Text to output Axis

And this showed me that the left trigger was being read as Infra, and had a floating point value of 1. The right trigger had a floating point number of -1 and no trigger being held down output a 0.

Throwing out some debug text to see axis values

Now that I could get the trigger inputs I could use them to do something cool, like for example change the material on a game object if I held the trigger down. Then change them back if I let go of the trigger.

I did this by first assigning 3 variables to store the default materials of the three planets. That way I could change the materials back to the original ones when I let go of the triggers.

Next up I had a condition that checked to see if the 'Infra' axis value was greater than 0.5. For some reason it instantiates at 0.014... so I couldn't use greater than 0. I'm not sure why it reads input like this then shoots back to 0. This might just be my old X360 pad's wear and tear.

But for now as a work around I just use the value 0.5. This means that if the left trigger is held down (axis 3 reads 1) the condition is true.

My Trigger Down Code

Now I just had to replace the debug code with the actual Infrared feature. To do this I assigned a public Material variable and used the engines Drag-and-drop method of attaching a placeholder Infrared material I whipped up. I did not hardcode the Infrared material into the script as I want the Astronautics department to be able to modify the material is they so choose. As Akshayan's idea about a modifiable system was a very good one. So for now I did this quick and dirty.

So the final code is pretty simple. I swap the materials from defaults to 'Infrared mode' while the left trigger is being held down (checked once per frame). And when I let go of the trigger (Axis 3 goes from 1 to 0) the default mats are loaded in again.

Swap Mats Code

The end result is a material swapping mechanic that can give us a cool infrared scanning mode!


Normal Mode
Scan mode!
Even though all the assets are placeholders and could look better, the mechanic works!

Other tasks done today:

  • Gave Matias and Konrad the contact details of the Kingston College staff member. This way they will be able to take point with this and gather the required information for their student feedback surveys. They will also need to make the amendments to the survey the tutor asked for. I figured this was better than me being an unnecessary middle man.
  • Got in touch with the technicians again to try and get my hands on the Oculus Rift. Was given details of two people who currently have the two DPK1's signed out. So my next step would be to contact them and ask if I could snag one for a day or so. Probably put this on the backburner until I have something concrete to test out since I don't want to waste peoples time.

No comments:

Post a Comment