Trio Game – Update

A new week and a new mechanic to incorporate in our trio game, in preparation for the upcoming exam. We’d be looking at projectiles and how to incorporate/instantiate them into games.

The example given to us had three different ways in which it could be used:

  1. An automatically fired projectile.
  2. A projectile that fires on a key press.
  3. A series of projectiles on a key press fired at angles around the player.

projectilesexample1

All very cool, however this needed adapting for use within our game ‘A Bouquet for My Lady’ so that the guards would fire a projectile at the player if they came too close. Feeling optimistic today I volunteered to be the one to take a stab at making this work.

Before I began playing with the code I knew I didn’t know how to give the guards a line of sight, for now I thought an easy way to get around this would be to give the guards a new collider that worked on trigger. To emulate a 4 directional line of sight I made a + sign out of the collider and prefabbed this onto the guards.

guardcollider

You can see above the original physics collider around the guard and the new trigger + collider. I’m honestly impressed with myself, I had a logical idea for once!

Currently this new collider didn’t do anything, so it was time to start cutting and pasting code together into something that would shoot a projectile. You can thank Kelly for reformatting the code into something a little neater, still getting used to ideal formatting.

projectilescript

As you can see we decided to use the multi-projectile shoot script and modify it. For simplicity we dialled the shots down to 4 each at an angle of 90º, so the guard would shoot up, down, left and right when the player crosses his path. Until we figure out something more complex this will do just fine.

The starting angle begins at 0º, the while loop begins and since the angle is not greater than 360º the projectile is instantiated and ‘fired’, the new current angle is 90º, less than 360º so fire again until we reach 360 and terminate the loop.

Other small changes made this week was adding tags for doors and the player. The guards new trigger collider was causing the player to exit the level after all flowers were collected and collided with a guard. Adding tags allowed us to add conditionals for the different tags, this way the player would ignore the guard triggers for exiting the level.

A small script was also added to change the door sprites after all flowers were collected to show to the player where they need to go. A nice little touch made easy thanks to the varied assets we’re using from kenney.nl.

All in all a solid week of progress, we’ll be adding more advanced guard scripts next week (line of sight) and will be shown a script for seeking objects to targets.

gameexample2

 

 

Advertisements

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