Friday, 17 January 2020

Scripting Interactions

I decided to focus more on gameplay today. One of the core mechanics of this genre back when it was first released and still holds true today (for this series anyway) is object interactions!
By this, I mean allowing the player to "inspect" objects and to be given a textual response, sometimes offering slight insight into the world. It took me a couple of hours to perfect but i'm proud of the script and logic I created.


There are basically 2 scripts I made, the first is a simple script with a string and a bool which I can attach to any designated trigger I want (right side of the above image). With this I've made it so that I can give each and every single object I attach it to it's own deliverable message. In addition I also added an optional "auto" feature which does the same, just saves the player manually interacting with it (I'm sure this isn't in the game, so I'm not sure how I will use it yet).
The second script (pictured to the left) checks these triggers for a collision with the player. If one is found the trigger transfers its message and auto status to the players empty message handler ready for use. Now if the player has pressed the button to interact with it, then the newly passed on message is displayed on screen via the UI. This also goes through a pre-check to see how many characters the string has, because if its too long the UI shifts to allow text wrapping on the next line.

Afterwards the message will dissapear once the player leaves the trigger. Or alternatively and more accuractly; the message dissapears if the trigger is interacted with a second time whilst never having left.


No comments:

Post a Comment