From 9b705e5044bebc7d4266d005d29d8fb5b78b74b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gervais?= Date: Fri, 8 Apr 2016 15:11:57 -0400 Subject: [PATCH] =?UTF-8?q?G=C3=A9n=C3=A9ration=20des=20ast=C3=A9roiride?= =?UTF-8?q?=20vers=20les=20players.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Asteroid.cs | 4 +- Assets/Scripts/AsteroidSpawner.cs | 37 ++++++++++++++---- Assets/Scripts/Astronaut.cs | 2 +- Assets/Scripts/PlanetManager.cs | 4 +- Assets/Scripts/testRotate.cs | 6 +-- Assets/_Scenes/planet.unity | 64 +------------------------------ 6 files changed, 40 insertions(+), 77 deletions(-) diff --git a/Assets/Scripts/Asteroid.cs b/Assets/Scripts/Asteroid.cs index 12c2107..56875e8 100644 --- a/Assets/Scripts/Asteroid.cs +++ b/Assets/Scripts/Asteroid.cs @@ -10,8 +10,8 @@ public class Asteroid : MonoBehaviour // Use this for initialization void Start() { - speed = Random.Range(0.1F, 2F); - print(speed); + speed = Random.Range(0.9F, 3F); + // print(speed); center = new Vector3(0, 0); } diff --git a/Assets/Scripts/AsteroidSpawner.cs b/Assets/Scripts/AsteroidSpawner.cs index f53a580..821fb83 100644 --- a/Assets/Scripts/AsteroidSpawner.cs +++ b/Assets/Scripts/AsteroidSpawner.cs @@ -7,9 +7,13 @@ public class AsteroidSpawner : TimerFunctionsClass public float NextSpawnTime = 1.0f; public GameObject AsteroidPrefab; + public bool GenerationVersLesjoueurs = true; //random lorsque false; // Use this for initialization - void Start () { + void Start () + { + + if (GenerationVersLesjoueurs) NextSpawnTime = 3 * NextSpawnTime; this.SetTimer(NextSpawnTime, SpawnAsteroidEvent); this.StartTimer(); } @@ -21,14 +25,33 @@ public class AsteroidSpawner : TimerFunctionsClass public void SpawnAsteroidEvent() { + if (!GenerationVersLesjoueurs) + { + // Random entre 10 et 20, * 1 ou -1 + var x = UnityEngine.Random.Range(10.0f, 20.0f)*(Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f))*2 - 1); + var y = UnityEngine.Random.Range(10.0f, 20.0f)*(Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f))*2 - 1); + + //instantiate as child of AsteroidSpawner + var a = Instantiate(AsteroidPrefab, new Vector3(x, y, 0.0f), Quaternion.identity); + //a.tranform.parent = this.transform; + + } + else + { + var players = GameObject.FindGameObjectsWithTag("Player"); + var planet = FindObjectOfType(); + foreach (var p in players) + { + var playerTheta = Mathf.Atan2(p.transform.position.y, p.transform.position.x); + var angle = ( 360.0f + (((playerTheta * 180)) / Mathf.PI)) % 360; ///TODO : a changer pour p.theta + print("angle:" + angle); + Instantiate(AsteroidPrefab, planet.GetPlanetCoordinatesFromPlayerXY(angle, UnityEngine.Random.Range(10f,15f)), Quaternion.identity); + } + + } + - // Random entre 10 et 20, * 1 ou -1 - var x = UnityEngine.Random.Range(10.0f, 20.0f) * (Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f)) * 2 - 1); - var y = UnityEngine.Random.Range(10.0f, 20.0f) * (Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f)) * 2 - 1); - //instantiate as child of AsteroidSpawner - var a = Instantiate(AsteroidPrefab, new Vector3(x, y, 0.0f), Quaternion.identity); - //a.tranform.parent = this.transform; //Cooldown untill next random spawn SetTimer(NextSpawnTime, SpawnAsteroidEvent); diff --git a/Assets/Scripts/Astronaut.cs b/Assets/Scripts/Astronaut.cs index 44e3a47..f0fb79f 100644 --- a/Assets/Scripts/Astronaut.cs +++ b/Assets/Scripts/Astronaut.cs @@ -137,7 +137,7 @@ public class Astronaut : MonoBehaviour { { Vector3 rotation = transform.rotation.eulerAngles; rotation.z = Mathf.Sin(walkTime*Mathf.PI)*50; - print("rotation " + rotation); + // print("rotation " + rotation); transform.rotation = Quaternion.Euler(rotation); yield return null; } diff --git a/Assets/Scripts/PlanetManager.cs b/Assets/Scripts/PlanetManager.cs index 6298910..f496eea 100644 --- a/Assets/Scripts/PlanetManager.cs +++ b/Assets/Scripts/PlanetManager.cs @@ -181,9 +181,9 @@ public class PlanetManager : MonoBehaviour public Vector3 GetPlanetCoordinatesFromPlayerXY(float playerLocalX, float playerLocalY) { var theta = playerLocalX; - var wedgeRadius = GetPlanetRadius(playerLocalX); + var wedgeRadius = GetPlanetRadius(playerLocalX) + playerLocalY; var x = wedgeRadius * Mathf.Cos(theta * Mathf.PI / 180); - var y = wedgeRadius * Mathf.Sin(theta * Mathf.PI / 180) + playerLocalY; + var y = wedgeRadius * Mathf.Sin(theta * Mathf.PI / 180) ; return new Vector3(x, y, 0); } diff --git a/Assets/Scripts/testRotate.cs b/Assets/Scripts/testRotate.cs index d80d6bd..bd587f5 100644 --- a/Assets/Scripts/testRotate.cs +++ b/Assets/Scripts/testRotate.cs @@ -68,10 +68,10 @@ public class testRotate : MonoBehaviour { // var x = r * Mathf.Cos(theta * Mathf.PI / 180); // var y = r * Mathf.Sin(theta * Mathf.PI / 180); // + y0 du player - var player = GameObject.Find("CubePlayer").gameObject; + // var player = GameObject.Find("CubePlayer").gameObject; //player.transform.position = Vector3.Lerp(player.transform.position, new Vector3(x, y, 0 ), Time.deltaTime); - player.transform.position = Vector3.Lerp(player.transform.position, - planet.GetPlanetCoordinatesFromPlayerXY(theta, 0f), Time.fixedDeltaTime); + // player.transform.position = Vector3.Lerp(player.transform.position, + // planet.GetPlanetCoordinatesFromPlayerXY(theta, 0f), Time.fixedDeltaTime); } } diff --git a/Assets/_Scenes/planet.unity b/Assets/_Scenes/planet.unity index d0b76cc..a382705 100644 --- a/Assets/_Scenes/planet.unity +++ b/Assets/_Scenes/planet.unity @@ -127,48 +127,7 @@ MonoBehaviour: textTime: NextSpawnTime: 1 AsteroidPrefab: {fileID: 160026, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} ---- !u!1001 &240262242 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalPosition.x - value: 8.22 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalPosition.y - value: 1.36 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 494682, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - propertyPath: m_RootOrder - value: 4 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - m_IsPrefabParent: 0 + GenerationVersLesjoueurs: 1 --- !u!1 &437600384 GameObject: m_ObjectHideFlags: 0 @@ -264,25 +223,6 @@ MonoBehaviour: CartierMaxRatio: 2 CartierStepSize: 0.25 WedgePrefab: {fileID: 170328, guid: 0b78da08dfa398840862539a74cc2377, type: 2} ---- !u!1 &475725347 stripped -GameObject: - m_PrefabParentObject: {fileID: 160026, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2} - m_PrefabInternal: {fileID: 240262242} ---- !u!54 &475725353 -Rigidbody: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 475725347} - serializedVersion: 2 - m_Mass: 1 - m_Drag: 0 - m_AngularDrag: 0.05 - m_UseGravity: 0 - m_IsKinematic: 1 - m_Interpolate: 0 - m_Constraints: 0 - m_CollisionDetection: 0 --- !u!1 &638371353 GameObject: m_ObjectHideFlags: 0 @@ -383,7 +323,7 @@ GameObject: - 114: {fileID: 1250089535} m_Layer: 0 m_Name: CubePlayer - m_TagString: Untagged + m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0