RSS

Scripting Time! Transmutation: Lighting

31 Jul

The game is set inside of a nuclear power plant, and nuclear power plants need siren lights in case of emergency right?

Siren Light.jpg

Like This One

My goal was to create something functionally identical to one of these siren lights. Surprisingly it was extremely easy. It took two lines of code.

Siren Light Code.JPG

Set a rotational speed, and make it rotate in the direction by (time x speed).

Light Gif.gif


Fiddling with such a simple light had my lighting senses tingling. I though what else needs some lighting? The elevator perhaps?

14012953_10206991253404328_1765396985_o.jpg

Inspiration piece. Yes I took a photo of an elevator.

Elevator Lights.JPG

Excellent! But perhaps they would be better off only activating when the elevator arrives? The elevator would need to know to activate it’s lights when it arrives. Because the elevator is already counting to when it arrives I could simply insert another method that would activate the lights.

Elevator Inside Lights.JPG

Elevator Lights Gif.gif


I felt like the elevator could be improved on just a little bit more. If the game is supposed to be 4 minutes long and the goal of the game is to escape via the elevator, there should be an indication of how close the elevator is to the 5th underground floor.

6 lights. From left to right (-5, -4, -3, -2, -1, Ground). Next was to change these lights to show the elevator moving.

The elevator would need:

  • An array of all of the lights. = GameObject[] lights;
  • Which is the current light. = int current Light;
  • Which light to change to.
  • The time since the game has started. = float lightTimer =  Time.time (in start).
  • How often the lights should change. = float lightRefreshTimer;

How often the lights should change is determined by the length of the game. If there are six lights, and the game is 4 minutes long, the light should change every lightRefreshTimer amount of seconds.

lightRefreshTimer = (elevatorTime / (amount of lights in the lights array – 1)). Because there are six lights, but the first one is already active, the elevator only has to move down 5 levels, not six.

So if the (Time.time – lightTimer >= lightRefreshTimer)) Change the lights() and refresh the time duration.

This slideshow requires JavaScript.

The SwitchLights() method sets the current light off, Changes the value to the next light, and turns that one on. Each time that method is called it changes the current light to the next one. But what happens if all of the lights have been changed and the timer is still going? I’d need a way for the last light to be the last light. Above the if statement to that checks if the Time.time – lightTimer >= lightRefreshTimer is another if statement. It checks if the current light isn’t greater than or equal to the amount of lights in the light array. If it isn’t it executes the code underneath, otherwise it doesn’t.

Something that tripped me up was not having the levelLights.length – 1.

Index out of array

The currentLight variable starts at 0 and only ever reaches 5. So when it comes around again to the levelLights.length (which is 6) it would try to activate something that wasn’t there. Hence having the -1 to the levelLights.length to make that also = 5.

Elevator Level Lights.gif

Until next time –

FeenikxFire

Nic

Advertisements
 
Leave a comment

Posted by on July 31, 2016 in C#, Game Dev

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: