public void UnlinkRight() { if (RightGrid == null) { return; } // unlink all the nodes for (int y = 0; y < kGridHeight; ++y) { SpringNode otherNode = RightGrid.GetNode(0, y); otherNode.Left = null; otherNode = RightGrid.GetNode(0, y - 1); if (otherNode != null) { otherNode.UL = null; } otherNode = RightGrid.GetNode(0, y + 1); if (otherNode != null) { otherNode.DL = null; } } RightGrid.LeftGrid = null; RightGrid = null; }
public void LinkRight(SpringGrid rightGrid) { if (RightGrid != null) { UnlinkRight(); } RightGrid = rightGrid; RightGrid.LeftGrid = this; for (int y = 0; y < kGridHeight; ++y) { // We leave the far-rightmost grid node as a mirror of the leftmost grid node in the next grid // So link the left-side nodes from the next grid to the 2nd-from-the-right nodes in this grid SpringNode thisNode = GetNode(kGridWidth - 2, y); SpringNode otherNode = RightGrid.GetNode(0, y); otherNode.Left = thisNode; otherNode = RightGrid.GetNode(0, y - 1); if (otherNode != null) { otherNode.UL = thisNode; } otherNode = RightGrid.GetNode(0, y + 1); if (otherNode != null) { otherNode.DL = thisNode; } } }
// Update is called once per frame void Update() { // HACK: handle pause because we don't handle it properly if (Time.deltaTime == 0) { return; } // TODO: We really only want to run simulation on segments near the player for (int i = 0; i < kNumSegments; ++i) { Grids[i].SimulateSpringForces(Time.deltaTime); } // Apply any other forces here (motion from player?) if (Player != null) { Vector3 playerPos = Player.transform.position; for (int i = 0; i < kNumSegments; ++i) { SpringGrid grid = Grids[i]; if (grid.InBounds(playerPos, ForceDist)) { float speed = Player.velocity.magnitude * (1.0f / 10.0f); // 10.0f = player max speed grid.AddOutwardForce(new Vector2(playerPos.x, playerPos.y), ForceDist * speed, ForcePower * speed * Time.deltaTime); } } } for (int i = 0; i < kNumSegments; ++i) { Grids[i].ResetNodePositions(); } for (int i = 0; i < kNumSegments; ++i) { Grids[i].UpdateSeams(); } for (int i = 0; i < kNumSegments; ++i) { Grids[i].TransferToMesh(); } }
void Awake() { SpringGrid prefabGrid = WavePrefab.GetComponent <SpringGrid>(); if (prefabGrid == null) { throw new Exception("WaveManager::Start: WavePrefab has no SpringGrid component"); } // Get data for the grid mesh MeshFilter filter = WavePrefab.GetComponent <MeshFilter>(); if (filter == null) { throw new Exception("WaveManager::Start: WavePrefab has no Mesh component"); } MeshIndices = SpringGrid.ImportMesh(filter.sharedMesh); // Allocate some shared temporary space Vector3[] tempPositions = new Vector3[SpringGrid.kGridHeight * SpringGrid.kGridWidth]; Color[] tempColors = new Color[SpringGrid.kGridHeight * SpringGrid.kGridWidth]; // Spawn the grids Grids = new SpringGrid[kNumSegments]; for (int i = 0; i < kNumSegments; ++i) { GameObject gridObj = GameObject.Instantiate(WavePrefab); gridObj.transform.SetParent(transform, false); SpringGrid grid = gridObj.GetComponent <SpringGrid>(); grid.Theta = i * SpringGrid.kThetaDelta; grid.Initialize(MeshIndices, tempPositions, tempColors); Grids[i] = grid; } // Link all the grids together for (int i = 0; i < kNumSegments - 1; ++i) { Grids[i].LinkRight(Grids[i + 1]); } Grids[kNumSegments - 1].LinkRight(Grids[0]); }
public override void onAddedToEntity() { _grid = entity.scene.findEntity("grid").getComponent <SpringGrid>(); }
public void UnlinkRight() { if (RightGrid == null) return; // unlink all the nodes for(int y = 0; y < kGridHeight; ++y) { SpringNode otherNode = RightGrid.GetNode(0, y); otherNode.Left = null; otherNode = RightGrid.GetNode(0, y - 1); if(otherNode != null) otherNode.UL = null; otherNode = RightGrid.GetNode(0, y + 1); if(otherNode != null) otherNode.DL = null; } RightGrid.LeftGrid = null; RightGrid = null; }
public void LinkRight(SpringGrid rightGrid) { if (RightGrid != null) UnlinkRight(); RightGrid = rightGrid; RightGrid.LeftGrid = this; for(int y = 0; y < kGridHeight; ++y) { // We leave the far-rightmost grid node as a mirror of the leftmost grid node in the next grid // So link the left-side nodes from the next grid to the 2nd-from-the-right nodes in this grid SpringNode thisNode = GetNode(kGridWidth - 2, y); SpringNode otherNode = RightGrid.GetNode(0, y); otherNode.Left = thisNode; otherNode = RightGrid.GetNode(0, y - 1); if (otherNode != null) otherNode.UL = thisNode; otherNode = RightGrid.GetNode(0, y + 1); if(otherNode != null) otherNode.DL = thisNode; } }
public override void OnAddedToEntity() { _grid = Entity.Scene.FindEntity("grid").GetComponent <SpringGrid>(); }