Hi,
For quite some time and with a lot of work, I try in vain to realize a C # script allowing to obtain a moving wall (scale on a growing single side) and where each time a key is pressed, the wall continues to advance at the same speed but by changing the angle of direction.
In this video clip from the movie Tron:
video link:
the wall behind each motorcycle looks like what I want to achieve on Unity with the difference that the angle of change of direction is not 90 ° or -90 °. It can be predefined by the instruction:
public float angle;
Here my main code but never success:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//pourquoi argument out of range exception ?
public class avec_new_itere_bis : MonoBehaviour
{
int q = 0;
public float angle_objet_initial, angle_Spawn2;
double dadaZ1 = 0;
public float vitesse_scale_Spawn2, rot_x, rot_y, rot_z;
public Mesh[] myMesh = new Mesh[10];
public GameObject Objet1;
double tmp = 0;
float angle;
Vector3 VSum = Vector3.zero;
Vector3 V;
//Vector3 pos;
List<GameObject> ObjectList;
List<double> dadaZ;
List<double> capt_temps;
List<Vector3> ListVecteurs;
List<double> Composante_X_de_somme_vectorielle;
List<double> Composante_Z_de_somme_vectorielle;
void Start()
{
dadaZ = new List<double>();
ObjectList = new List<GameObject>();
capt_temps = new List<double>();
ListVecteurs = new List<Vector3>();
Composante_X_de_somme_vectorielle = new List<double>();
Composante_Z_de_somme_vectorielle = new List<double>();
ObjectList.Add(Objet1);
dadaZ.Add(dadaZ1);
ListVecteurs.Add(VSum);
Composante_X_de_somme_vectorielle.Add(0);
Composante_Z_de_somme_vectorielle.Add(0);
capt_temps.Add(tmp);
capt_temps[0] = 0;
//dadaZ[0] = dadaZ1;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.I))
{
q++;
while (q < 1)
{
print("échelle_locale_z de l'objet initial à l'instantiation de son Spawn toto1 :" + dadaZ[0]);
print("-------------------------------------------------");
break;
}
//VSum = V1;
//q++;
//double dadaZSum = 0;
double SumVectorX = 0;
double SumVectorZ = 0;
VSum = Vector3.zero;
capt_temps.Add(tmp);
dadaZ.Add(dadaZ1);
ListVecteurs.Add(V);
capt_temps[q] = Time.time;
dadaZ[q - 1] = vitesse_scale_Spawn2 * (capt_temps[q] - capt_temps[q - 1]);//dadaZ[0] pas défini ici dadaZ[q] défini pour q>=2
//dadaZ[q] = vitesse_scale_Spawn2 * (Time.time - capt_temps[q - 1]);
//dadaZ[q] = 1;//tous les Spawn se placent au même endroit
angle = (q - 1) * angle_Spawn2;
ObjectList[q] = new GameObject("toto" + q);
Composante_X_de_somme_vectorielle.Add(dadaZ[q] * Mathf.Sin(angle_objet_initial + angle));
Composante_Z_de_somme_vectorielle.Add(dadaZ[q] * Mathf.Cos(angle_objet_initial + angle));
//ListVecteurs[q]= new Vector3((float)(dadaZ[q] * Mathf.Sin(angle_objet_initial + angle)), 0, (float)(dadaZ[q] * Mathf.Cos(angle_objet_initial + angle)));
ListVecteurs.Add(new Vector3((float)(dadaZ[q - 1] * Mathf.Sin(angle_objet_initial + angle)), 0, (float)(dadaZ[q - 1] * Mathf.Cos(angle_objet_initial + angle))));
foreach (Vector3 v in ListVecteurs)
{
VSum += v;
}
foreach (double X in Composante_X_de_somme_vectorielle)
{
SumVectorX += X;
}
foreach (double Z in Composante_Z_de_somme_vectorielle)
{
SumVectorZ += Z;
}
ObjectList[q].transform.position = VSum;// new Vector3((float)(dadaZ[q]* Mathf.Sin(angle_objet_initial+angle)),0, (float)(dadaZ[q]* Mathf.Cos(angle_objet_initial+angle)));
ObjectList[q].transform.localEulerAngles = new Vector3(rot_x, rot_y + angle + angle_Spawn2, rot_z);
ObjectList[q].transform.localScale = new Vector3((float)0.4, (float)6.975, 0);//le scale ne démarre pas à 0
ObjectList[q].AddComponent<MeshRenderer>();
ObjectList[q].AddComponent<MeshFilter>().mesh = myMesh[q];
//ObjectList[p].AddComponent<scale_one_side>().vitesse_scale_Spawn = vitesse_scale_Spawn2;
ObjectList[q].AddComponent<scale_to_0>().vitesse_scale_Spawn = vitesse_scale_Spawn2;
Destroy(ObjectList[q - 1].GetComponent<scale_to_0>());
Destroy(ObjectList[0].GetComponent<scale_one_side>());
print("échelle_locale_z du toto" + (q - 1) + " à l' instantiation de son Spawn toto" + q + " :" + dadaZ[q - 1]);
print("-------------------------------------------------");
print("comosante_x de position du toto" + q + " à l' instantiation de son Spawn toto" + (q + 1) + " :" + (float)(dadaZ[q - 1] * Mathf.Sin(angle_objet_initial + angle)));
print("comosante_z de position du toto" + q + " à l' instantiation de son Spawn toto" + (q + 1) + " :" + (float)(dadaZ[q - 1] * Mathf.Cos(angle_objet_initial + angle)));
print("-------------------------------------------------");
print("comosante_somme_x de position du toto" + q + " à l' instantiation de son Spawn toto" + (q + 1) + " :" + (float)(dadaZ[q - 1] * Mathf.Sin(angle_objet_initial + angle)));
print("comosante_somme_z de position du toto" + q + " à l' instantiation de son Spawn toto" + (q + 1) + " :" + (float)(dadaZ[q - 1] * Mathf.Sin(angle_objet_initial + angle)));
print("-------------------------------------------------");
/*while (q >= 2)
{
print("échelle_locale_z du toto" + (q - 1) + " à l' instantiation de son Spawn toto" + q + " :" + dadaZ[q - 1]);
print("-------------------------------------------------");
break;
}*/
print("##########################################################");
}
}
}
Here the second script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class scale_one_side : MonoBehaviour
{
public float vitesse_scale_Spawn;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 pos = transform.localScale;
pos.z = vitesse_scale_Spawn * (Time.time);//erreur:à l'instant où tu génères Spawn2,Time.time n'est pas nul
transform.localScale = pos;
}
}
Here the third script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class scale_to_0 : MonoBehaviour
{
public float vitesse_scale_Spawn;
List<double> capture_temps;
double temps;
int p = 0;
int l;
// Start is called before the first frame update
void Start()
{
//transform.localScale = new Vector3((float)0.4, (float)6.975, 0);//e scaleZ ne démarre pas à 0
capture_temps = new List<double>();
capture_temps.Add(temps);
capture_temps[0] = Time.time;
// transform.localScale = new Vector3((float)0.4, (float)6.975, 0);
}
// Update is called once per frame
void Update()
{
Vector3 POS = transform.localScale;
//pos.z = vitesse_scale_Spawn * (Time.time);
// transform.localScale = new Vector3((float)0.4, (float)6.975, 0);
//POS.z = (float)(vitesse_scale_Spawn * (Time.time - capture_temps[0]));
if (Input.GetKeyDown(KeyCode.I))
{
p++;
capture_temps.Add(temps);
capture_temps[p] = Time.time;// - capture_temps[0];
//transform.localScale = new Vector3((float)0.4, (float)6.975, 0);
//pos.z = (float)(vitesse_scale_Spawn * (capture_temps[p] - capture_temps[p - 1]));//erreur:à l'instant où tu génères Spawn2,Time.time n'est pas nul
for (l = 0; l <p; l++)
{
print("scale_to_0 de l'objet :" + l + "=" + POS.z);
}
print("----------------------");
}
//transform.localScale = new Vector3((float)0.4, (float)6.975, 0);
POS.z = (float)(vitesse_scale_Spawn * (Time.time - capture_temps[p]));
transform.localScale = POS; //avec + newVector3((float)0.4) ça génère faussement à partir d'une échelle nulle
}
}
Can you help me in this serious project?
thanks