Пример #1
0
 private void MoveChildrenObj(float dt)
 {
     if (!groupFollows || !parentObject.isRootOfGroup)
     {
         return;
     }
     if (parentObject.group == null)
     {
         return;
     }
     if (dt == -1f) //initialize "points","vys" (children -> position,Y-speed)
     {
         points.Clear();
         vys.Clear();
         foreach (var child in parentObject.group.objects.Where(p => p != parentObject))
         {
             points.Add(child.m_position);
             vys.Add(initialSpeed.y);
         }
     }
     else if (dt == -2f) //reset "points" (children -> position)
     {
         int i = 0;
         foreach (var child in parentObject.group.objects.Where(p => p != parentObject))
         {
             child.m_position = new Vector3(points[i].x, points[i].y, points[i].z);
             i++;
         }
     }
     else if (dt == -3f) //reset "vys" (children -> Y-speed)
     {
         int i = 0;
         foreach (var child in parentObject.group.objects.Where(p => p != parentObject))
         {
             vys[i] = initialSpeed.y;
             i++;
         }
     }
     else //update "child.m_position","vys"
     {
         int i = 0;
         foreach (var child in parentObject.group.objects.Where(p => p != parentObject))
         {
             vys[i]           = vys[i] - gravity * dt;
             child.m_position = new Vector3(
                 child.m_position.x + dt * initialSpeed.x,
                 child.m_position.y + dt * vys[i],
                 child.m_position.z + dt * initialSpeed.z);
             if (child.m_position.y < ProceduralUtils.NearestGroundPointVertical(child.m_position).y)
             {
                 child.m_position.y = child.m_position.y - dt * vys[i];
                 vys[i]             = -vys[i] * bounceFactor;
             }
             i++;
         }
     }
 }
Пример #2
0
 public override void UpdateModule(ProceduralObjectsLogic logic, bool simulationPaused, bool layerVisible)
 {
     if (!state)
     {
         point0 = new Vector3(parentObject.m_position.x, parentObject.m_position.y, parentObject.m_position.z);
     }
     else if (!simulationPaused && layerVisible)
     {
         float dt = Time.deltaTime * timeSpeed;
         MoveChildrenObj(dt);
         vy = vy - gravity * dt;
         parentObject.m_position = new Vector3(
             parentObject.m_position.x + dt * initialSpeed.x,
             parentObject.m_position.y + dt * vy,
             parentObject.m_position.z + dt * initialSpeed.z);
         if (parentObject.m_position.y < ProceduralUtils.NearestGroundPointVertical(parentObject.m_position).y)
         {
             parentObject.m_position.y = parentObject.m_position.y - dt * vy;
             vy = -vy * bounceFactor;
             if (t > 0)
             {
                 t--;
             }
             else if (t == 0 || vy < 0.1f)
             {
                 if (!repeat)
                 {
                     state = !state;
                 }
                 else
                 {
                     t = bounceTimes;
                     parentObject.m_position = new Vector3(point0.x, point0.y, point0.z);
                     vy = initialSpeed.y;
                     MoveChildrenObj(-2f);
                     MoveChildrenObj(-3f);
                 }
             }
         }
     }
 }