Hi everybody !
I got a problem, I’m trying to animate a list of GameObject from their localposition.
The goal is to create a kind of levitation of those objects, like the pod in starwars.
I’m trying to store the initial position to go back to her after a move to never be to far from my original point.
I think I’m in a wrong way and after like aaaaaaaaaall day long I’m still in the same point.
Here is the code I wrote :
using UnityEngine;
using System.Collections;
public class Levitation : MonoBehaviour {
private GameObject[] Planes;
private Vector3[] PosInitiales;
private Vector3[] PosNew;
private float randamFloatX;
private float randamFloatY;
private float randamFloatZ;
private bool NewValue = true;
private float T;
private float timeToWait = 1f;
private float startTime;
void Awake(){
Planes = GameObject.FindGameObjectsWithTag ("LevitationObject");
PosInitiales = new Vector3[Planes.Length];
for (int i = 0; i < Planes.Length; i++) {
PosInitiales _= Planes*.transform.localPosition;*_
* }*
* }*
* // Use this for initialization*
* void Start () {*
* randamFloatX = Random.Range(-0.1f, 0.1f);*
* randamFloatY = Random.Range(-0.1f, 0.1f);*
* }*
* // Update is called once per frame*
* void Update () {*
* if(NewValue == true){*
* StartCoroutine ( WaitAndMove(timeToWait));*
* startTime = Time.time;*
* }*
* T = (Time.time - startTime) / 1f;*
* foreach(GameObject PlanesToMove in Planes){*
* PosNew = new Vector3[Planes.Length];*
* for (int ib = 0; ib < Planes.Length; ib++) {*
* PosNew[ib] = Planes[ib].transform.localPosition;*
* for (int i = 0; i < Planes.Length; i++) {*
_ if(PosNew[ib] != PosInitiales*){*_
_ PlanesToMove.transform.localPosition = PosInitiales*;
}
if(PosNew[ib] == PosInitiales){
float lerpX = Mathf.Lerp(PlanesToMove.transform.localPosition.x, (PlanesToMove.transform.localPosition.x+randamFloatX), T);
float lerpY = Mathf.Lerp(PlanesToMove.transform.localPosition.y, (PlanesToMove.transform.localPosition.y+randamFloatY), T);*_
* PlanesToMove.transform.localPosition = new Vector3(lerpX, lerpY, PlanesToMove.transform.localPosition.z);*
* }*
* }*
* }*
* }*
}
* IEnumerator WaitAndMove(float waitTime){*
* NewValue = false;*
* yield return new WaitForSeconds(waitTime);*
* randamFloatX = Random.Range(-0.1f, 0.1f);*
* randamFloatY = Random.Range(-0.1f, 0.1f);*
* NewValue = true;*
* }*
}
Help me before I start to be crazier than I already am