Lock-on system

Following up on our shooting overhaul, we decided to look into a lock on system that would simplify shooting so we could let the player put a lot more focus into dodging obstacles, an aspect from our previous version that we didn’t want to lose.

I started to delevop a system that automatically fired bullets using pooling (to further reduce lag through the use of recycling). The way this worked is that the bullets would only fire when the mouse is over an enemy.

LO01

Bullets firing towards confirmed target along with lock-on animation

 

reticle_animation_placeholder_by_squirrelkidd-d9j49w1

lock-on animation

I created this lock-on animation in Flash through the use of classic and color tweens. This animation would follow the mouse while locking on and then stay in place once it had locked on. While this is a good step towards visual feedback of locking on I still feel like we need something more impactful to go with this to let the player know that they have locked onto the enemy, I was thinking possibly we could have it so the enemy flashes white for a brief second once they’ve been targeted.

Bullet firingcode:

	void Update ()
	{
//FIRE ON MOUSEOVER
		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		RaycastHit hit; 

		if(!Physics.Raycast(ray, out hit))
		{

			canFire = false;
			LockToggle = false;
			CancelInvoke ("Fire");
			return;
		}
		else
		{
			Debug.Log (hit.collider.gameObject);
			canFire = true;
			LockToggle = true;
			SpawnLockOn ();
			lockOnEffect.SetActive(true);
			Invoke("Fire",fireTime);
		}
//FIRE ON CLICK
		if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
			{
//				canFire = true;
				Debug.Log (hit.collider.gameObject);
//				LockToggle = true;
//				SpawnLockOn ();
//				lockOnEffect.SetActive(true);
				Invoke("Fire",fireTime);				
			}
			else	
			{		
//				canFire = false;
			}
//
	}

	void Fire()
	{
		GameObject obj = NewObjectPoolScript.current.GetPooledObject(); //fires bullet

		if (obj == null) return;


		obj.transform.LookAt (EnemyDie.markedObject.transform);
		obj.transform.rotation = transform.rotation;
		obj.SetActive(true); //fires bullet

		firing = true;

	}
	
	void SpawnLockOn()
	{
		if (LockToggle == true && ReLockOk == true)
		{
		Debug.Log ("Spawned lock on");
		LockToggle = false;
		ReLockOk = false;
		}
	}

 

EDIT: 20/11/15

We had to scrap this idea due to a bug – bullets would ricochet between enemies (example: a bullet would fly through an enemy destroying it, then the bullet would change direction after another enemy is clicked). Also sorting out storing the marked enemies and shooting more than one of them was proving to be too time consuming, we didn’t want to have that working and nothing else. I am going to have to change the shooting system a third time and come up with something simple for the time being; I may be able to edit the ‘Fire on click’ section of my code to salvage something though.

 

 

 

 

 

 

 

 

 

 

Leave a comment