Wednesday, 6 April 2016
Craig Lang - Adapting Scripts
Death and Stones:
Even though some of my scripts were broken I was able to salvage some of them. I used the attacking script for every item which can kill the player, such as the spikes and boulders. I used the throw and collected stone scripts and rescripted them, so the boulders fall independently on a loop rather than the player having control.
There was a lot of tweaking with the scripts. I created a coroutine for the attacking script so that when the player enters a collider of an enemy object such as the boulder the death screen will display and the player is transported to the spawn area. I created the spawn area earlier using a box trigger and a tag on the object. I still need to create the menus for the game so there is no death screen at the moment.
For the falling boulder I created two coroutines within the throw rock script. The first coroutine is the thorw. This enables the object to transform and rotate as it falls towards the ground. The second coroutine is the timer, which destroys the object. I used waitforseconds in both coroutines which calls the other after a certain amount of time. The second script for the stone movement controls the speed and plays a sound when it comes into contact with any object tagged ground.
After a lot of tweaking I got the boulder to fall at a steady pace over time and even roll off the edge. Unfortunately the objects do not destroy themselves. This isn't a huge issue, but I will need to revisit this at some point to correct the issue.
Moving Platforms:
I managed to salvage the array and coroutine script originally used for the AI patrolling script for the platforms. I simply attached the script to the platforms I wanted to move and added objects tagged with "Set Path" to the array. The platform will move back and forth between the objects listed in the array tagged "Set Path". However even though this worked the player would not move along with the platform. This caused the player to fall off and made it hard to play. After research on unity forums I found out a way to solve this issue. By making the character a parent of the platforms when they enter the trigger the player will remain attached to the platform as it moved. The player will till be able to move without threat of losing control. The player will then be unparented when they exit the trigger. This was achieved simply by using OnTriggerEnter/Exit(Collider Other).
Labels:
Craig Lang,
Scripting,
Unity
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment