I decided to remove the MoveForward script from the GameplayPlane group containing the camera and ship and scroll the plane texture using an offset code, giving the illusion that the player is moving when they aren’t.
I also added a global static variable to this that speeds up as the game progresses with the Time.time code. I plan of referencing this in other codes such the the MoveForward code so that obstacles and enemies will come at the player faster as the game progresses.
Texture Scroll code:
public float scrollSpeedY = 5.00f;
public float scrollSpeedX = 0.00f;
public static float updatedSpeed = 0f;
public float YSpeed = 0f;
public float maxSpeed = 20f;
void FixedUpdate()
{
scrollSpeedY = (scrollSpeedY * YSpeed);
updatedSpeed = (scrollSpeedY * Time.time);
float offset = updatedSpeed;
float offset2 = Time.time * scrollSpeedX;
renderer.material.mainTextureOffset = new Vector2(offset2,-updatedSpeed);
if (updatedSpeed > maxSpeed)
updatedSpeed = maxSpeed;
if (scrollSpeedY > maxSpeed)
scrollSpeedY = maxSpeed;
if (PlayerDie.PlayerAlive == false)
{
// YSpeed = (YSpeed * -YSpeed);
}
}
}
I added a particle effect to the back of the ship to give it more of an animated look and to add to the illusion of it moving when it’s in place. It does look quite extreme though, it could fit depending on how fast the objects are coming towards the player but it looks a bit awkward as the ship turns as the trail just points away from where the player is pointing.
I was able to create a parallax effect by using the texture offset code on these cloud textures that I had put on planes and stretched to give the illusion they’re moving faster. The parallax came from slowing down the texture speed by having a lower scroll speed variable for textures on further planes.

Alpha channel of cloud texture
I set up a game manager script which allowed me to spawn objects from a certain distance. I planned to use this to spawn enemies, objects, and pickups.
GameManager script:
using UnityEngine;
using System.Collections;
public class SpawnerObjCustom : MonoBehaviour {
public GameObject enemy;
public int enemyCount;
public float spawnWait;
public float startWait;
public float waveWait;
public float maxEnemies = 5f;
public float minX = -5.5f;
public float maxX = -5.5f;
public float minY = -5.5f;
public float maxY = -5.5f;
// Use this for initialization
void Start ()
{
StartCoroutine(SpawnWaves ());
}
// Update is called once per frame
void Update () {
}
IEnumerator SpawnWaves()
{
if (enemyCount < maxEnemies)
{
yield return new WaitForSeconds (startWait);
while(true)
{
for(int i = 0; i < enemyCount; i++)
{
//Make an enemy
Vector3 spawnPosition = new Vector3(Random.Range (minX, maxX), Random.Range (minY, maxY), 30);
Instantiate(enemy, spawnPosition, enemy.transform.rotation);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
}
}
}
}
Malakai sent me a basic enemy model for us to use as a placeholder for the final enemy model. I set this up in the game manager to spawn an enemy from a distance.

By using my ‘LookAt’ and ‘EnemyAttack’ scripts I was able to create a complex enemy tracking system in which each enemy is assigned a value from 1-5 and there are 5 points on an invisible spinning disc. The next step is for me to get the enemies to repeat this same behavior on a similar object set behind the player, only after a number of seconds have passed.

Enemy tracking system finalized (Final build image, edited into post)
LookAt script:
public GameObject target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
transform.LookAt(target.transform);
}
}
EnemyAttack script:
using UnityEngine;
using System.Collections;
public class EnemyAttackA : MonoBehaviour
{
public GameObject player;
public GameObject target2;
public float smoothing = 1f;
public float stopDis = 1f;
public int randomEnemy;
public float waitTime = 15f;
private int currentTrack;
// private int currentTrack;
private bool finalAttack;
// Use this for initialization
void Start ()
{
GameObject spawnObj = GameObject.FindGameObjectWithTag ("GameManager");
currentTrack = spawnObj.GetComponent ().currentTrackNum();
Debug.Log (currentTrack);
randomEnemy = Random.Range (0, 4);
//for (int i = 0; i < 4; i++) { player = GameObject.Find ("EnemyPoint" + currentTrack); //} target2 = GameObject.Find ("EnemyTimeUp"); StartCoroutine(AttackPattern()); Invoke ("FinalAttack",6); } // Update is called once per frame void Update () { // Debug.Log (Time.deltaTime); } IEnumerator AttackPattern() { while(Vector3.Distance(transform.position, player.transform.position) > stopDis)
{
if(!finalAttack)
{
transform.position = Vector3.Lerp(transform.position, player.transform.position, (smoothing * Time.deltaTime));
}
else
{
transform.position = Vector3.Lerp(transform.position, target2.transform.position, (smoothing * Time.deltaTime));
}
yield return null;
}
print("Reached the target.");
yield return new WaitForSeconds(waitTime);
{
while(Vector3.Distance(transform.position, player.transform.position) <= stopDis)
{
print("Enemy leaving screen.");
transform.position = Vector3.Lerp(transform.position, target2.transform.position, smoothing * Time.deltaTime);
}
}
}
void FinalAttack()
{
finalAttack = true;
}
}
I added trails to the tip of the ship via empty gameobjects set as children. However since the ship is actually not moving forward the trail does not show up unless I move up, down, left or right with the arrow keys. I find this annoying as it breaks the illusion slightly, I may switch it back to the previous method I was using before and try and get the same setup working with the MoveForward script on the plane parent.

Added a barrel roll easter egg (Double tap E)
I decided to turn the mesh renderer off on the bullet prefab after discovering how to use trails as I applied it to the prefab and it gave a smoother looking streamlined beam look.

The enemies contain a script that causes them to destroy themselves on contact with bullets and instantiate an empty gameobject prefab that has a explosive particle effect on them with the same colour. The empty gameobject also plays a death sound on awakening.
EnemyDie script:
using UnityEngine;
using System.Collections;
public class EnemyDie : MonoBehaviour {
public float lifeTime = 2f;
public Rigidbody explode;
public float explodeVelocity = 10.0f;
// Use this for initialization
void Start ()
{
//explode.Pause();
}
// Update is called once per frame
void Update ()
{
//Destroy (gameObject, lifeTime);
//replace this with fly away over time
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "Bullet")
{
Rigidbody newTrail = Instantiate(explode,transform.position,transform.rotation) as Rigidbody;
newTrail.AddForce(transform.forward*explodeVelocity,ForceMode.VelocityChange);
Destroy (gameObject);
}
}
}
I created an object that could be controlled using the arrow keys that will later be transformed into a controllable aiming reticle. The LookAt script was used on the ship so it would always face the reticle no matter what, and it could still be controlled seperately from the reticle as it uses the WASD keys instead of the arrow keys.

I later on replaced this controllable box and the two distance-judging reticle placeholders with a square with an self-illuminated alpha reticle texture.

Reticle texture
