keskiviikko 13. joulukuuta 2017

Unity platformer - hanging

NME17AP

Lukuvuosi 2017-2018

We're going to make hanging mechanics for the character. For this assignment you'll need to have two more animations to your character: hanging idle and movement animations. Also create a platform that has vines below it.

Create your hanging animations and link them in them in the animator window. Create two new bool parameters for idle and moving hanging.



Next add new FSM component for the player. This FSM has four states, two global events: hang & don't hang and three normal events: left, right & drop.


The first state has don't hang as a global transition. It also has four actions. First action is set property in which you'll need to drag and drop the player movement FSM component to target object section. Remember to tick the enabled box. This will make the movement FSM active when player is not hanging.

Second and third actions are both set animator bool. Select your hanging and idle hanging parameters to it and don't click the value box because we want those animations to be inactive in this state.

Last action in this state is set property. Drag the rigidbody 2D component to the target object section and select gravity scale as property and 1 for the value. This makes gravity active when the player is not hanging.


Next state has the global hang event as well as left, right and drop event.

You'll need same four actions as you had in the first state, so copy and paste those from that state to this one. This time the set property for the player movement FSM has no tick in the set value box and gravity scale is set to 0. Also tick the value box for the set animator bool action for idle hanging.

Add three get key down actions. Select key D for the first one and make it send right event. Next select key A and make it send left event. Last get key down action has S as the key and it sends drop event.


Third state is for hanging and moving. In this state you'll need five actions and two events: drop & finished. First action is set animator bool which has the parameter hanging activated. Second event is get key down. In this action choose S as the key and make it send drop event which is linked back to the first state. Third action is get key up. Choose A as the key which sends the finished event back
to the first state. Fourth action is set scale. This is needed when player changes direction. If the player faces right by default then you'll need -1 in the x axis. Last action is translate which is used to move player. Put a number in the x axis section. If player moves left then you'll need to add minus sign before the number.


Last state is similar to the third state. Just change D to the get key up action and don't put negative numbers to set scale and translate actions.

Then create new FSM for the hanging platform. This FSM has three states and two events: activate hanging & deactivate hanging.


First state has trigger 2D event action. Choose player as collide tag and make it send activate hanging event.

Second state has also trigger 2D event action. This time choose on trigger exit 2D for the trigger section, player as collide tag and make it send event deactivate hanging. Second action for this state is send event by name. This send information for the player hanging FSM so that it knows to activate hanging mode. Choose game object FSM for the event target, remember to select specify game object and drag the player object to it. Choose your hanging FSM for the FSM section and select the global hang event to the send event section.


Last state has also the send event by name action. Now write don't hang in the send event section and otherwise keep it same as before.



perjantai 1. joulukuuta 2017

Unity platformer - enemy

NME17AP

Lukuvuonna 2017-2018

This time we're going to create a Mario game styled enemy. Player will take damage from the enemy if he bumps into it from the side. Player can also kill the enemy by jumping on top of it.

First you need to make changes to your health bar. If you haven't created global float variable for health. Do so by choosing global variables tab and write a name for your float variable. Also set it to 1 which is the players max health.



Create FSM for the health bar. This FSM will have two states and one event in it.


First state has the float changed action. This will check every frame if the health float is changed. If the global health variable is changed the the state will send the fill event.


Second state has the set property event. We need to change the property of the UI sprite, so drag and drop your health UI component to the target object section. Select fill amount as the property and your health variable to the set value section. Make this state send finished event and link the transtion back to the first state.

Next import your enemy sprite to the game and drag it to the scene. If you have idle, movement and death animations for the enemy then create them as well and connect those in the animator window similarly to the player animator.

Create two box colliders for the enemy. One box collider is normal sized while the other is small box on top of the enemy. Click the trigger option active for the small box.


Then it's time to choose FSM component. First FSM will do damage to the player. For this FSM you'll need three states, one event called damage and one global event called no damage. First state has a collision 2D event action.  Select the player as collide tag and make the action send damage event.


Second state has float subtract action. Select the player health as the float variable and 0.25 as the value for subtract section. Add wait action and wait for 1 second before sending finished event.


Third state has global no damage transition. This is done by clicking the state with the right mouse button and selecting global transition. This state will be activated when the player kills the enemy so that the player will not take damage while enemy goes through its death animation.

Next create new FSM component for the enemy. This will be the enemy death FSM. You'll need three states and one event called enemy death.


First state has trigger 2D event action. Choose player as collide tag and your enemy death event for the send event section.

Second state has 4 different actions. First action is set animator bool. This action is needed if the enemy has a death animation because the animation will be activated in this state. Second action is set property. For this you'll need to drag the collider that has no trigger to the target object section and select enabled to property. Third action is send event by name. In this state you'll send the no damage event to the enemy's player death FSM. Last action is wait in which you'll need to wait time it takes for the enemy to complete the death animation and after that make this action to send finished event.



Last state in the enemy death FSM has the destroy self action which will destroy the enemy and remove it from the game.



sunnuntai 19. marraskuuta 2017

ANIMAATIO- JA PELIHISTORIA

NME17AP

Lukuvuosi 2017-18


Animaatio- ja pelihistoriaan tutustuminen harjoitustehtävien avulla.


Vastaukset tai linkki vastauksiin palautetaan sähköpostin liitteenä Harrille.

Palauttakaa mielellään kaikki tehtävät kerralla.


ANIMAATIOHISTORIA:


"Animaatiolla ja elokuvalla on yhteinen historia, joten animaation syntyyn vaikuttaneet tapahtumat ovat pitkälti samoja kuin elokuvan.

Taiteessa on vuosisatojen kuluessa usein esiintynyt pyrkimystä liikkeen kuvaamiseen. Varhaisimmat tunnetut liikesarjat löytyvät egyptiläisistä seinämaalauksista n. 2000 vuotta ennen ajanlaskumme alkua. Leonardo da Vincin tunnetuimpiin teoksiin kuuluu kehän ympäröimä mies, jonka raajat kuvataan useissa asennoissa.

Itse animaatio on kulkenut pitkän tien ennakkoluulottomista kokeiluista ja nerokkaasta taiteesta kaupallisuuden kautta tekniseen ihannointiin. 1900-luvun alusta tähän päivään animaation tie on taiteelliselta kannalta katsottuna ollut enimmäkseen alamäkeä.

Mutta kun kaupallisuuden lait alkavat tuottaa tarpeeksi merkityksetöntä ja sielutonta ”viihdettä”, ja tekninen kikkailu saapuu tiensä päähän, löytyykö silloin jokunen palavan innostunut animaation tekijä kääntämään kehityksen suunnan?

Aika näyttää, ja menneestä ajasta tämäkin alkaa…" (ML)

Tehtävä 1:

Varhaisia kojeita

Etsi tietoa jostakin elokuvan syntyyn liittyvästä varhaisesta optisesta keksinnöstä.

Esimerkkejä:
Mutoskooppi
Fenakistiskooppi
Zoetrooppi
Laterna magica
Stereoskooppi
Kinematografi
Kinematoskooppi
Camera lucida
Elektrotachyskooppi
Thaumatrooppi

Kirjoita 1 A4-sivun pituinen kirjallinen kuvaus valitsemasi kojeen historiasta ja
toiminnasta.

Tehtävä 2:

Valitse seuraavista essee-aiheista yksi mieleisesi ja kirjoita siitä noin 1 A4-sivun
pituinen essee.

Esseen aiheet:

1. Animaatiostudiot USA:ssa
Kirjoita valitsemasi animaatiostudion historiasta, tuotannosta ja merkityksestä
animaation kehityksen kannalta. Disney, Warner bros. MGM, Pixar…

2. Tex Avery – Animaatiohistorian suurin nero?
Esittele kyseinen henkilö ja hänen tuotantonsa ja perustele/kumoa hänen
neroutensa paitsi omilla mielipiteilläsi, myös kylmillä tosiasioilla!

3. Animen ja mangan suosio japanissa
Pohdi esseessäsi Japanin historiaan, kulttuuriin ja yhteiskuntaan liittyviä
seikkoja, jotka ovat mahdollistaneet animen ja mangan yhteiskunta- ja ikärajat
ylittävän suosion.

4. Eadweard Muybridge - Mies joka keksi animaation?
Kirjoita essee tämän eriskummallisen miehen elämästä ja varsinkin hänen merkityksestään animaation synnyssä ja kehityksessä.



PELIHISTORIA:


Tehtävä 1:

Pelitutkimus (ludologia)

Pelitutkimus alkoi itsenäistyä 1990-luvun lopussa, kun ludologia teki pesäeron narratologiasta.
Narrativistit halusivat rinnastaa pelit tarinoita kertoviin välineisiin, kuten kirjallisuus, elokuvat ja teatteri.
Ludologien mielestä pelejä pitää tutkia peleinä, eli sääntöihin, käyttöjärjestelmiin ja pelaamiseen perustuvina järjestelminä.

Mene osoitteeseen: www.pelitutkimus.fi

Sivun yläreunasta löydät linkit pelitutkimuksen vuosikirjoihin 2009-2015. Valitse vuosikirjoista yksi artikkeli tai katsaus. Tee siitä 1 A4 sivun mittainen tiivistelmä. Älä käytä artikkelin tai katsauksen valmista tiivistelmää, vaan tiivistä itse.


Tehtävä 2:

Videopelaamisen historiaa

Käy katsomassa videopelaamisen historian aikajanaa seuraavasta linkistä:

http://prezi.com/olihyz7-iea4/pelihistoria/


Tehtävä 3:

Japanin pelikulttuuri

Kirjoita 1 A4-pituinen essee Japanin pelikulttuurista ja –historiasta.

Tässä vähän pohjustusta:

Machiko Kusaharan artikkelissa ”Japanin pelikulttuuri” pohditaan varsinkin konsolipelaamisen suosion syitä Japanissa. Käsitys siitä, että vain lapset pelaavat tietokone- ja konsolipelejä, juontaa juurensa meidän länsimaisen yhteiskuntamme suhtautumisesta pelaamiseen, tai oikeammin leikkimiseen: leikki on lasten työtä. Kusaharan mukaan Japanissa, jossa varsinkin konsolipelaaminen kukoistaa, ei tällaista ajattelutapaa ole. Siellä kaikki pelaavat. Pelaamisen suosiota voisi verrata Mangan, japanilaisen sarjakuvan suosioon, joka ylittää kaikki ikään, sukupuoleen, tai sosiaaliseen asemaan liittyvät rajat. Mistä tämä suosio sitten johtuu? Jo 1100-luvun japanilaisessa runoudessa esiintyy leikkimistä arvostavia säkeitä. Leikkimistä ja pelaamista on siis varsin pitkään pidetty normaalina inhimillisen elämän osana. Perheiden yhteiseen ajanviettoon on vuosisatoja kuulunut pelien pelaaminen, ja 1900-luvun loppupuoliskolla myös intohimoinen television katselu. Nämä molemmat kulttuuriset tekijät yhdistyivät sitten sujuvasti konsolipelien pelaamiseen 1980- ja 1990-luvuilla (Huhtamo & Kangas, 2002, s. 269-272).


Tehtävä 4:

Valitse seuraavista tehtävistä toinen ja tee se:

1. Nostalgiaa



Valitse haluamasi tietokone- tai videopeli 1980- tai 90-luvulta. Tee siitä ja sen historiasta sähköinen esittely esim. Prezillä tai Swayllä.

2. Ilmiöt ja genret

Tee sähköinen esittely jostain pelikulttuurin ilmiöstä tai genrestä, esimerkiksi:

MMO / MMORPG
LARP
Arcade-hallit
Play-by-Mail / Play-by-Email / Play-by-Web
Kilpapelaaminen
Casual gaming
Ammattipelaaminen
Magic The Gathering

Jos ei näistä löydy kiinnostavaa aihetta, niin keksi oma ja esittele se.

perjantai 17. marraskuuta 2017

Unity platformer - Mouse controlled menu

NME17AP

Lukuvuonna 2017-2018

Previously we did menu screen that was controlled with keyboard. This time we're going to make menu screen in which you can select to start or quit the game with a mouse click.

For this exercise you need to install NGUI and NGUI Playmaker events. You can find the install link for PlaymakerNgui package in here.


For the NGUI events to work, you need to find a prefab called NGUI Playmaker Proxy from the Playmaker NGUI folder. Drag and drop the prefab to the hierarchy window.


After installing these packages and adding NGUI Playmake Proxy to the hierarchy, select NGUI -> create -> label from the top toolbar.

You need to create 3 labels. One for the game name, one for starting the game and one for exiting the game.

Then select the start game label and create a new component called box collider for it. Make the collider same size as the start game widget. This will be the area that the player is able to click with mouse.


You'll also need to find a component called ngui playmaker events and after that create new FSM for the start label.

For the start FSM create two more states in addition to the start state. Click the first state in the FSM with right mouse button. Select add transition -> custom events -> NGUI -> on hover enter.


Second state has two transitions: on hover exit & on click. On hover transition means that the player can hover mouse over the label and it affects the label in some way. Link the transition according to the picture below.


In the first state you're going to set color for the label. This color will be shown when player is not over the label and it's not active. To select the color property lock the FSM so that it will always be active.


The go to the label from which you need to drag and drop the label to the state window. Grab the UI label (script) text and drag it to the first state of the start FSM.



Next select the color you want to be displayed when the player is not over the label from the property option.




Do the same for the second state but now choose a different color that you want to be displayed when the player is hovering over the label.



It the last state you'll need action called load level. Write the name of the level you want to load when player clicks the start label.



Now do the same thing for the exit label. In the last state choose application quit action so that the game closes when player clicks exit.



tiistai 7. marraskuuta 2017

Unity platformer - moving platforms and parenting

NME17Ap

lukuvuosi 2017-2018

There are multiple ways to do moving platforms with playmaker. The easiest is to use I Tween actions. Start by creating FSM for the moving platform. In this FSM we need two states. Link the states with finished event. 


Now in the first state you need to find action called I Tween Move To. This automatically moves the object to desired position. Select the vector position according to your object transform. If you want to move object vertically on y axis then change those values and same goes for horizontal x axis. I wanted the platform to move horizontally so I changed the values on the x axis. Remember to change the y axis value too, if your object has other than 0 for the value on that axis.  Then define the speed you want for your platform movement.  Remove check marks from orient to path and move to path. Remember to put your finished event in finish event location. Then copy the action to the other state but change the value for the x axis so it matches the original position of the platform.


Second way to do a moving platform is with animation. You need to choose object you want to animate and in the animation window click create new animation. You'll need to create folder in the project for your animations and save the animation under appropriate name.




Next you are going to make the animation. This is done by adding property and choosing transform position. Click on the time line and create a new key by moving the platform to the desired position. Do this few times and make sure the animation goes smoothly back to the position it started from. You can copy keyframes by choosing a frame and pressing ctrl + c. Then choose other place from the timeline and press ctrl + v to paste the frame.



You can test the animation by pressing play button from the animation window. When you are satisfied with the result stop recording by pressing the record button (red dot) in the animation window. Now when you test the game the animations you have made, they will play automatically.


Last thing we are going to do is make the platforms parented with the character. If this is not done and the character is on the platform, it will not move along with the platform. This might work as a feature in the game for horizontally moving platforms. For the vertically moving platforms it might not be a good idea because it can cause some twitching. So that's why you should use parenting for moving platforms.

Create new FSM for the character. In the first state use collision 2D event action.  You'll have to create new tag for the moving platforms because this action uses collide tag to recognize which object you are colliding with. You'll also need to create new variable. This time the variable type needs to be gameobject because you're going to use it for storing the collider. When you store the collider, you can use it later in the next state. Then we need to sent event to activate the next state.



In the next state use set parent action. Use the gameobject variable we created before. This will set the parent according to the last moving platform the character has collided with. Then you want to add one state before returning to the start state. In that state use the action wait for 0.1 seconds. This prevents creating an infinite loop which will result in error.


You'll also need to make changes in the jumping FSM. In the third state you need to create two new actions. One is collision 2D event because you want to prevent the player for using jump while in air with the moving platforms too. Then there's the set parent action. This time don't choose anything for the parent. It will make the character independent object again and it won't move with the platforms while jumping.