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
119
120
121
122
123
124
125
126
127
128
129
130
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;

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

	private GameObject currentEnemyTarget;

	private static float HERO_MIN_RANGE = 1000.0f;
	private static float HERO_MAX_RANGE = 2000.0f;

	float genCoord(float min_distance, float max_distance) {
		return (Random.value - Random.value) * (min_distance + Random.value * (max_distance-min_distance));
	}

	void Start()
	{
		this.transform.position = new Vector3(
			genCoord(HERO_MIN_RANGE, HERO_MAX_RANGE),
			genCoord(HERO_MIN_RANGE, HERO_MAX_RANGE),
			genCoord(HERO_MIN_RANGE, HERO_MAX_RANGE) 
		);
	
		this.transform.rotation = Random.rotation;

		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, this.transform.position, this.transform.rotation);
			CommunicationCenter.Instance.DestroyOneAlly(this.gameObject);
			Destroy(this.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);

			Vector3 relative = enemyShip.position - transform.position;
			float distance = relative.magnitude;
			if(distance<300)
			{
				StopThruster();
			}
			else
			{
				StartThruster();
			}

			if ((distance<2000) && (Vector3.Dot (relative, transform.forward)>0.5) && (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
134 Diff Diff DRuega picture DRuega Fri 07 Nov, 2014 18:48:12 +0000

In GameManager ho aggiunto HandleWeaponHit per centralizzare e generalizzare la gestione degli impatti delle armi (SU_LaserShot e Missile).
Ho modificato i parametri dei nemici per renderli più aggressivi.

131 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 18:25:48 +0000

Merge.

130 Diff Diff LMancini picture LMancini Thu 06 Nov, 2014 18:03:48 +0000
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 FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 14:21:59 +0000