示例#1
0
 void UpdateDownwardsForces()
 {
     if (WaterGrid != null)
     {
         foreach (var Origin in DownwardsRaycastOrigins)
         {
             Ray DownwardsRay = new Ray(Origin.transform.position, new Vector3(0.0f, -1.0f, 0.0f));
             var waterBitMask = 1 << 4;
             if (Physics.Raycast(DownwardsRay, out raycastResult, DefaultDistanceFromWater, waterBitMask))
             {
                 GameObject obj = raycastResult.collider.gameObject;
                 if (MassSpringSystem.IsMassUnit(obj.tag))
                 {
                     Vector3 p        = obj.transform.position - WaterGrid.GetUnitOffset();
                     float   pressure = SimulatedPressure * Origin.Force;
                     if (Body != null)
                     {
                         pressure *= Mathf.Clamp(Body.mass / MaxMass, 0.0f, 1.0f);
                     }
                     //need to translate back from unity world space so we use z here rather than y
                     WaterGrid.GridTouches.Add(new Vector3(p.x, p.z, pressure));
                 }
             }
         }
     }
 }
示例#2
0
    /** Cast a ray from the given screen position and check for collision with mass objects.
     *  If there is a collision with a mass object, add a touch point to the grid touches array
     *  (e.g. to be later be handled by a MassSpringSystem controller).
     */
    public void ProjectScreenPositionToMassSpringGrid(Vector2 screenPosition)
    {
        Ray ray = Camera.main.ScreenPointToRay(screenPosition);

        if (Physics.Raycast(ray, out raycastResult))
        {
            GameObject obj = raycastResult.collider.gameObject;
            if (MassSpringSystem.IsMassUnit(obj.tag))
            {
                Vector3 p = obj.transform.position;
                //need to translate back from unity world space so we use z here rather than y
                GridTouches.Add(new Vector3(p.x, p.z, SimulatedPressure));
            }
        }
    }
示例#3
0
 // Use this for initialization
 void Start()
 {
     TerrainFrontStartPosition = TileFront.position;
     TerrainBackStartPosition  = TileBack.position;
     PlayerStartPosition       = Player.transform.position;
     PlayerStartRotation       = Player.transform.rotation;
     SpawnIslands(TileFront, ref IslandsFront);
     SpawnIslands(TileBack, ref IslandsBack);
     if (WaterGridBack != null)
     {
         WaterSpawnerBack = WaterGridBack.GetComponent <MassSpawner>();
         WaterSystemBack  = WaterGridBack.GetComponent <MassSpringSystem>();
     }
     if (WaterGridFront != null)
     {
         WaterSpawnerFront = WaterGridFront.GetComponent <MassSpawner>();
         WaterSystemFront  = WaterGridFront.GetComponent <MassSpringSystem>();
     }
     PlayerForceController = Player.GetComponent <WaterForceController>();
 }