Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using UnityEngine;
using System.Collections;

public class AllyShip : MonoBehaviour 
{

	public SU_Thruster[] thrusters;
	public float rollRate = 100.0f;
	public float yawRate = 30.0f;
	public float pitchRate = 100.0f;
	public Vector3[] weaponMountPoints;	
	public Transform[] laserShotPrefab;
	public AudioClip[] soundEffectFire;
	public CameraFollow followCamera;
	public float life = 100;
	private bool isAlive = true;
	public int ID;
	private Transform _transform;

	private Rigidbody _cacheRigidbody;
	private float shootFreq = 1f;
	private float lastShootTime = 0;
	private int weaponType = 0;

	private GameObject currentEnemyTarget;


	void Start()
	{

		_transform = transform;

		foreach (SU_Thruster _thruster in thrusters)
		{
			if (_thruster == null) 
			{
				Debug.LogError("Thruster array not properly configured. Attach thrusters to the game object and link them to the Thrusters array.");
			}
		}
		_cacheRigidbody = rigidbody;
		if (_cacheRigidbody == null) 
		{
			Debug.LogError("Spaceship has no rigidbody - the thruster scripts will fail. Add rigidbody component to the spaceship.");
		}
	}

	public void getHitted(float hit)
	{
		if(!isAlive) return;
		
		life -= hit;
		if(life<=0)
		{
			isAlive = false;
			Instantiate(GameManager.Instance.explosionEffect, _transform.position, _transform.rotation);
			CommunicationCenter.Instance.DestroyOneAlly(_transform.gameObject);
			Destroy(_transform.gameObject);
		}
	}


	void StartThruster()
	{
		foreach (SU_Thruster _thruster in thrusters) 
		{
			_thruster.StartThruster();
		}
	}
	void StopThruster()
	{
		foreach (SU_Thruster _thruster in thrusters) 
		{
			_thruster.StopThruster();
		}
	}
	void Update()
	{
		lastShootTime+=Time.deltaTime;
		if(currentEnemyTarget==null)
		{
			//Debug.Log ("Find target");
			currentEnemyTarget = GameManager.GetClosestEnemy(transform);
		}
		if(currentEnemyTarget)
		{
			Transform enemyShip = currentEnemyTarget.transform;
			Debug.DrawLine(transform.position, enemyShip.position, Color.yellow);

			transform.LookAt(enemyShip);

			if(Vector3.Distance(transform.position,enemyShip.position)<300)
			{
				StopThruster();
			}
			else
			{
				StartThruster();
			}
			if(lastShootTime>shootFreq)
			{
				lastShootTime=0;
				foreach (Vector3 _wmp in weaponMountPoints) 
				{
					// Calculate where the position is in world space for the mount point
					Vector3 _pos = transform.position + transform.right * _wmp.x + transform.up * _wmp.y + transform.forward * _wmp.z;
					// Instantiate the laser prefab at position with the spaceships rotation
					Transform _laserShot = (Transform) Instantiate(laserShotPrefab[weaponType], _pos, transform.rotation);
					// Specify which transform it was that fired this round so we can ignore it for collision/hit
					_laserShot.GetComponent<SU_LaserShot>().firedBy = transform;
				}
				if (soundEffectFire[weaponType] != null) 
				{
					audio.PlayOneShot(soundEffectFire[weaponType]);
				}
			}
		}
	}
}

Commits for Nextrek/3DSpace/Assets/Custum/Scripts/AllyShip.cs

Diff revisions: vs.
Revision Author Commited Message
127 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 16:52:49 +0000

Aggiungo PilotNameGenerator.cs

Genera nomi random alle navi... così sembra più figo :) :)

126 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 14:45:25 +0000

Cleanup, warnings e altre minchiate :)

125 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 13:44:02 +0000

Migliorata la ricerca del nemico più vicino pesando di più la differenza angolare.
Migliorato lo script dei missili.

122 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 10:12:00 +0000

Tocco Magico :P
1) Centralizzata creazione navi
2) Levato dove possibile *.Instance.spaceShip
3) Implementato GameManager.GetClosestEnemy usato da Ally. In un secondo momento va messo nella logica del missile.
GetClosestEnemy usa una funzione score valutando distanza e angolo; Privilegia obiettivi sul vettore forward.

120 Diff Diff LMancini picture LMancini Wed 05 Nov, 2014 18:41:05 +0000
119 Diff Diff LMancini picture LMancini Wed 05 Nov, 2014 15:33:48 +0000
112 Diff Diff FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 14:21:59 +0000
107 FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 11:56:46 +0000